I was always somewhat annoyed by the fact that I could not use the same "enhanced" syntax with the LaTeX terminals as with the interactive terminals. While an optimal result certainly involves using proper LaTeX commands, an automatic translation using "enhanced" mode might just be good enough in many cases and makes re-use of gnuplot code simpler. Also it enables using more of the demos, which is interesting for testing LaTeX terminals. It has been on my TODO list for a long time.
The attached patch applies to the latex
terminal as found in my "latex-terminal" branch - but may be easily adopted for current HEAD and other LaTeX terminals. The implementation uses gnuplot's enhanced recursion parser - as most (all other?) terminals do it. A separate parser for LaTeX only might have some benefits but bears the risk of code duplication and needs additional maintenance.
The output of "enhanced" mode is text mode only, i.e. no math mode is involved. It supports super- and subscripts using \textsuperscript
and \textsubscript
commands. Boxes with no width ('@') are handled using zero-width boxes \makebox[0pt][l]
and hidden text ('&') produces a \phantom
box. Overprinting is not supported and nested super- and subscripts are currently not handled.
Font size changes are handled using \large
and similar commands. Bold and italic attributes are supported, but the font face is currently ignored.
The aim of this patch is to trigger discussion if an "enhanced mode" for LaTeX terminals is actually useful for others, too. And to get feedback on the actual implementation. Note that I am not a LaTeX expert, so feedback is very much appreciated.
As an example, output of enhanced_utf8.dem
compiled with xelatex is attached.
Attached is an improved update which applies to current head. It handles nested super- and subscripts. That turned out to be a bit more complicated than expected. Still it fails in some cases in combination with & and @ commands.
I would be happy to see discussion.
My current impression was that people using the latex terminals were doing so primarily because they wanted latex processing of the text, otherwise why bother?
I can also see why as a developer it would be convenient to run the demo set through latex terminals without triggering errors, but that seems like an issue specific to developers rather than general users. Also for this purpose it would be sufficient to strip out the enhanced text markup altogether rather than trying to convert it to latex.
There is a related problem that hits me when running test cases through a latex terminal. Autogenerated titles that contain an underscore character cause the latex processing to fail. For example:
plot 'rgb_variable.dat'
fails because the default key entry contains an underscore in the file name. In this case it is specifically non-enhanced text. It would be convenient to deal with this automatically by escaping reserved latex characters. Several other terminals already do something similar, e.g. svg and html output requires replacing ampersand with something else.
Please note that escaping tilde ~ , backslash \ and circumflex ^ characters is a slightly more involved than prepending \ . In particular backslashes might turn up in auto-keys of filenames on Windows.
For the enhanced text mode, I had been toying with the idea to make the replacement optional with escape/noescape terminal options and to restrict it to enhanced mode only. The later was done in order to have a possibility to turn it off per label. But we could add a "noescape" option to labels and keys like the "noenhanced" option - or just apply it to auto-generated labels and keys.
Here's my code:
https://sourceforge.net/u/markisch/gnuplot/ci/fc5339011e8e9c6604ea9883547dfa72e9493664/
I don't understand. The possibility of having backslash in a filename is just one more reason that the autogenerated title must be checked for special characters. I attach a patch that does this, although I'm still mulling over whether this is the best approach.
Sorry for being negative, but I'm still unclear on why the older latex terminals (latex/emtex/eepic/tpic/...) are needed at all. Is there a reason that TeX users would not be able to use tikz? Tikz does such a dramatically better job with the graphics that it makes output from the older terminals look horrible by comparison. Also its handling of text means that escaping the auto-generated title is as simple as wrapping it with \verb@title@.
If the concern is backwards compatibility with old scripts written specifically for the old terminals, then adding support for new features is not relevant.
Last edit: Ethan Merritt 2018-06-27
I see several arguments for having an "enhanced" treatment also for LaTeX terminals:
As a further step we could detect math mode $...$ and deactivate enhanced text mode processing there. That way mixing both notations would be trivial.