2012-11-20 2 views
1

Я генерации участок в R и сохранить его как PDF с:Некорректно признал математический символ из PDF в LaTeX

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} 

Но вместо μ знак бесконечности (∞ ) отображается.

Почему?

+2

Какой PDF-ридер вы используете? Он отлично выглядит в читателе Adobe Acrobat, но неправильно, как вы говорите в Evince ... Я думаю, что это проблема кодирования ... – Spacedman

+0

@Spacedman Хм, действительно! Я использую Adobe Acrobat и TeXStudio PDF Viewer. –

+1

Хотите скриншоты? Если вы прочитаете справку (pdf), она расскажет о таких проблемах. – Spacedman

ответ

0

Для бесшовной интеграции без проблем с кодированием я бы посмотрел на пакет «TikzDevice». Он выводит изображения Tikz в формате LaTeX. Например:

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.

Смежные вопросы