daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
https://daqana.github.io/tikzDevice
132 stars 26 forks source link

glossary with tikzDevice #144

Closed amit2011 closed 6 years ago

amit2011 commented 8 years ago

Hi, I am using tikzDevice to run my R-scripts within latex.

This is my code --

\documentclass{article}
\usepackage[acronym]{glossaries}
\usepackage{tiki} 

\makeglossaries

\newacronym{gcd}{GCD}{Greatest Common Divisor}

\newacronym{lcm}{LCM}{Least Common Multiple}

\begin{document}

    Given a set of numbers, there are elementary methods to compute 
    its \acrlong{gcd}, which is abbreviated \acrshort{gcd}. This 
    process is similar to that used for the \acrfull{lcm}.

    \begin{figure}[!ht]
    \centering
    \input{rtikzFile}
    \end{figure}

\end{document}

where rtikzFile is created using R as follows --

library(tikzDevice)
tikz("rtikzFile.tex" )
options( tikzLatexPackages = c( getOption( "tikzLatexPackages" ), "\\usepackage[acronym]{glossaries}"))
plot(1,1,xlab="XXX")
dev.off()

`

Now, I would like to use \gls{lcm} instead of XXX as x-label. I have tried using \\gls\\{lcm\\} and also \\gls{lcm}. Everything just return errors, something like --

File: pgfcorepathusage.code.tex 2013/12/13  (rss-revision 1.23)
\Error in getMetricsFromLatex(TeXMetrics, verbose = verbose) : 
TeX was unable to calculate metrics for the following string
or character:

    \gls\{lcm\}
krlmlr commented 8 years ago

Doesn't the glossary require two LaTeX compilation passes? Unless you manage to link the preamble to a precompiled glossary file, the measurement will be off anyway.

The development version will show you the location of the generated .tex and .log files, I've attached them for your convenience.

tikzStringWidthCalc.log.txt tikzStringWidthCalc.tex.txt

amit2011 commented 8 years ago

Right, even it would need \makeglossariesin the preamble. Is there a way to pass precompiled glossary file to the r-script ?

krlmlr commented 8 years ago

Honestly, I have no idea. I'd probably use a simpler approach, e.g., use the raw text in the plots and later do a text substitution in the generated .tex file.

amit2011 commented 8 years ago

ok. I already tried to edit it in generated .tex file, as expected, that works perfectly. Thanks for pointer to the problem.