Menu

#771 "Enhanced" mode for LaTeX terminals

Version 5
open
nobody
5
2018-06-22
2018-06-17
No

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.

3 Attachments

Discussion

  • Bastian Märkisch

    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.

     
  • Ethan Merritt

    Ethan Merritt - 2018-06-22

    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.

     
    • Bastian Märkisch

      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/

       
      • Ethan Merritt

        Ethan Merritt - 2018-06-27

        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
  • Bastian Märkisch

    I see several arguments for having an "enhanced" treatment also for LaTeX terminals:

    • Consistency (least surprise). [Although expectations may vary. But "enhanced" is default for all terminals that support it now.]
    • Text size estimates are much better for enhanced mode than they are for TeX code and hence graphs need less tweaking of offsets etc. (But I haven't checked with my implementation for LaTeX yet.)
    • Mixing "enhanced" and TeX labels can help in the gradual transition from "interactive" terminals to LaTeX graphs for publication. For labels without math mode the "enhanced" mode might be good enough already.
    • Dual use is simplified: users might like to have EMF/PNG versions of a plot e.g. for presentation and a LaTeX version for inclusion in a document.
    • The "demo" argument is not only valid developers. In many cases the demos are HOWTO guides and users might expect to be able to try them with any terminal.
    • But then again the test-suite character of the demos is reason enough to make enhanced text mode at least "compilable". I agree that "stripping out" the enhanced text notation would be OK in that case.
    • It was rather straightforward to do. (Not an actual reason for keeping it...)

    As a further step we could detect math mode $...$ and deactivate enhanced text mode processing there. That way mixing both notations would be trivial.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.