【问题标题】:Incorrectly recognized math symbol from PDF in LaTeX在 LaTeX 中错误识别 PDF 中的数学符号
【发布时间】:2012-11-20 14:29:02
【问题描述】:

我正在 R 中生成绘图并将其另存为 PDF,其中:

pdf(
  file='Plots/errors.pdf',
  height=4,
  width=7,
  onefile=TRUE,
  family='Helvetica',
  pointsize=12
)

# Here is my graphics

dev.off()

我在图形内部的某个地方:

mtext(
  expression(mu[H1])
)

它可以生成整洁的 PDF,并带有正确处理的希腊字母 µ

然后我将这个 PDF 导入到 LaTeX 文章中:

\includegraphics[width=1\textwidth,height=0.4\textheight]{../Plots/errors.pdf} 

但显示的是无穷大 () 符号而不是 µ

为什么?

【问题讨论】:

  • 您使用的是什么 PDF 阅读器?它在 Adob​​e Acrobat 阅读器中看起来不错,但就像你在 Evince 中所说的那样错误......我认为这是一个编码问题......
  • @Spacedman 嗯,真的!我正在使用 Adob​​e Acrobat 和 TeXStudio PDF 查看器。
  • 你想要截图吗?如果您阅读帮助(pdf),它会讨论这样的问题。
  • @Spacedman 谢谢,我想help(pdf) 就足够了。 :)

标签: r math pdf latex pdf-generation


【解决方案1】:

对于没有编码问题的无缝集成,我会查看包“TikzDevice”。它以 LaTeX 格式输出 Tikz 图像。例如:

require(tikzDevice)


setwd("/Path/To/LaTeX/Files/")

#Names of LaTeX symbols
syms <- c('alpha', 'theta', 'tau', 'beta', 'vartheta', 'pi', 'upsilon', 'gamma', 'varpi', 'phi', 'delta', 'kappa', 'rho', 'varphi', 'epsilon', 'lambda', 'varrho', 'chi', 'varepsilon', 'mu', 'sigma', 'psi', 'zeta', 'nu', 'varsigma', 'omega', 'eta', 'xi', 'Gamma', 'Lambda', 'Sigma', 'Psi', 'Delta', 'Xi', 'Upsilon', 'Omega', 'Theta', 'Pi', 'Phi')
len <- length(syms)

# random colors (red, green, blue)
r <- round(runif(len), 2)
g <- round(runif(len), 2)
b <- round(runif(len), 2)

# calculate dummy data points
x <- runif(50,1,10)
y <- x + rnorm(length(x))
fit <- lm(y ~ x)
rsq <- summary(fit)$r.squared
rsq <- signif(rsq,4)

# plot the result, will create symbol-regression.tex in the working
# directory the first time this is run it may take a long time because the
# process of calulating string widths for proper placement is
# computationally intensive, the results will get cached for the current R
# session or will get permenantly cached if you set
# options( tikzMetricsDictionary='/path/to/dictionary' ) which will be
# created if it does not exist.  Also if the flag standAlone is not set to
# TRUE then a file is created which can be included with \include{}

tikz('symbolr.tex', width = 4,height = 4,pointsize = 12)

# The syntax is mar=c(bottom, left, top, right).
par(mar=c(2,2,2,2))
# plot the box and the regression line
plot(x, y, type='n', xlab='', ylab='')
box()
abline(fit)

# add the latex symbols as points
text(x, y, paste('\\color[rgb]{',r,',',g,',',b,'}{$\\',syms,'$}',sep=''))
# Display the correlation coefficient
mtext(paste("Linear model: $R^{2}=",rsq,"$" ),line=0.5)
# and the equation of the line
legend('bottom', legend = paste("$y = ", round(coef(fit)[2],3),'x +', round(coef(fit)[1],3), '$',  sep=''), bty= 'n')

# Close the device
dev.off()

那么您所要做的就是将刚刚从 R 输出的文件包含在您的 LaTeX 文档中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2010-11-09
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    相关资源
    最近更新 更多