Open zackw opened 12 years ago
Just out of curiosity: why do you even want (the ugly) plotmath when you can write native (beautiful) LaTeX expressions in your plots with tikzDevice?
I have a great many plots to convert from the stock PDF device + plotmath to tikzDevice. This is yet another hurdle.
I can see the value of plotmath support for cases where the source code that produces a plot is difficult to change---such as plotting functions buried inside of 3rd party packages.
However, achieving this would take quite a bit of work. One would need to develop a hash that mapped all the Adobe Symbol glyphs used by plotmath
to their LaTeX equivalents and then write a function that used the hash to perform substitutions in strings sent to the device---this could probably be worked into the existing sanitization machinery.
Right now I don't have the time to start such a project and, as Yihui mentioned, native LaTeX expressions work so much better that I don't even use plotmath
anymore so my motivation for this is low.
However, I would be more than willing to review and merge a pull request that added this functionality.
Right now I don't have the time to start such a project and, as Yihui mentioned, native LaTeX expressions work so much better that I don't even use
plotmath
anymore so my motivation for this is low.However, I would be more than willing to review and merge a pull request that added this functionality.
I'm not familiar with how this stuff works internally. Is there a point at which the device has an opportunity to inspect and rewrite the plotmath expression? If so, it seems like it would be fairly straightforward, although a fair bit of coding, to convert that into an equivalent TeX math expression. Or does the device only see plotmath after it's been converted into a sequence of low-level drawing operations?
I'm not familiar with how this stuff works internally. Is there a point at which the device has an opportunity to inspect and rewrite the plotmath expression? If so, it seems like it would be fairly straightforward, although a fair bit of coding, to convert that into an equivalent TeX math expression.
I don't know if this is possible---one would have to work their way through the function calls, starting with plot
, to see what happens to the expression
object and if there is a point where custom code could be hooked on.
Or does the device only see plotmath after it's been converted into a sequence of low-level drawing operations?
All text sent to the device is passed through a sanitization routine. This would be a good place to implement an Adobe Symbol -> LaTeX Math conversion. At the C level, there is a function call that hands the string off to some R-Level code for processing:
https://github.com/Sharpie/RTikZDevice/blob/0.6.2/src/tikzDevice.c#L1958
It wouldn't be hard to extend this function call to pass a flag that indicated if the string to be sanitized contained Adobe Symbol glyphs. I could take care of this part.
The rest of the job would be adding code to:
https://github.com/Sharpie/RTikZDevice/blob/0.6.2/R/sanitizeTexString.R
That swapped the symbol glyphs for LaTeX statements---this is the part that I don't have the time to dig into.
I'm not familiar with how this stuff works internally. Is there a point at which the device has an opportunity to inspect and rewrite the plotmath expression? If so, it seems like it would be fairly straightforward, although a fair bit of coding, to convert that into an equivalent TeX math expression.
I don't know if this is possible---one would have to work their way through the function calls, starting with
plot
, to see what happens to theexpression
object and if there is a point where custom code could be hooked on.
A little poking at the R source tree gives me the impression there is no such hook. I might ask on r-devel, though, since that seems like the superior option (taking full advantage of TeX's math engine).
https://github.com/Sharpie/RTikZDevice/blob/0.6.2/R/sanitizeTexString.R
That swapped the symbol glyphs for LaTeX statements---this is the part that I don't have the time to dig into.
I don't have time right now either, but may try to find time in January or February.
zw
Plotmath expressions are not handled really at all by tikzDevice; anything that uses
%operators%
causes the string sanitizer to barf, Greek letters show up as the Latin letter corresponding to the position of the character in the Adobe Symbol font, and those are just the problems I've noticed so far.Ideal behavior would be for the device to translate plotmath into proper TeX math expressions, but I've no idea how difficult that would be.
Concrete test case 1:
Concrete test case 2:
-->
To be clear, I see this as a feature request rather than a bug, and I do have a workaround (edit all my graphics and replace plotmath with proper TeX math).