Inkscape.org
Beyond the Basics Using Matrices in PDF-LaTeX Export
  1. #1
    mvscheven mvscheven @mvscheven

    In the export to combined PDF-LaTeX-Format ampersands in text fields are escaped since version ~0.92, as the contents of text fields is placed in a tabular environment.

    We are experiencing problems with this when using matrices with the bmatrix environment inside a text field. Inside the bmatrix ampersands are needed as column separators. Placing the bmatrix inside a tabular does not cause a problem, because when removing the \ in front of the ampersands in the pdf_tex file the exported files can be used. But of course this manual modification destroys the automated process of including inkscape graphics in LaTeX documents.

    Did anybody else already experience this problem? Is there a solution without modifications to inkscape?

    Thanks for any advice!
    Malte

  2. #2
    Patrick Storz Patrick Storz @Ede_123

    Hi Malte,

    off-hand I don't think there's a solution except for modifying the file manually.

    If you have a good idea how this could be solved in Inkscape itself (without re-implementing a LaTeX parser in Inkscape) I'm all ears, though! I'm the one responsible for introducing the tabular environment, as it seemed to be the best option to get horizontal alignment of text right (a feature I assume many people use). At the same time this obviously required us to escape plain text ampersands, so they would not be used for alignment inside the tabular.

    Overall I've not found a great solution to achieve both simplicity (type what you want and have LaTeX typeset it beautifully) and at the same time be able to type any LaTeX without limitations. If in doubt I decided in favor of simplicity, though, as people should usually just type what they mean, not include a lot of LaTeX code.

    Cheers
    Patrick

  3. #3
    mvscheven mvscheven @mvscheven

    Hi Patrick,

    thanks a lot for your open and detailed answer, which made me look at the problem from a more general point of view and I came to the conclusion that escaping the ampersands should not be the default behaviour. Let me explain why:

    Using Inkscape for the combined Pdf/LaTeX-Export the user does not expect a WYSIWYG behaviour for the text fields, as the font, size and style is defined by the LaTeX document and not ba Inkscape. The text fields used in Inkscape are more like LaTeX source code fragments. Therefore I would expect the true LaTeX behaviour also for these text fields in Inkscape.

    In LaTeX the ampersand cannot be used as it is also outside of tabular or array environment. It must always be escaped, also in plain text. Therefore, for me (and probably many LaTeX-Inkscape users) it is absolutely natural to escape ampersands also in Inkscape text fields if I plan a combined Pdf/LaTeX-Export. There are more characters that must be escaped in LaTeX (e.g. \, $, #, %, _) and for those this is still necessary in Inkscape. If somebody escapes the ampersand in Inkscape this will lead to "\\&", i.e. a visible backslash in the output and an error message due to a misplaced alignment tab character.

    There are a few exceptions for this behaviour, like the \verb command or environment. Inside the \verb command all characters can be used without escaping, but Inkscape will escape the ampersand and by this modify the visible output.

    Also before introducing the tabular environment for the combined export, ampersands needed to be escaped in Inkscape. So both modifications are not really related or depend on each other.

    So, in my opinion escaping the ampersands is causing much more problems then it might avoid. Therefore I would like to ask you and the team to reconsider this decision.

    Best regards,
    Malte

  4. #4
    Patrick Storz Patrick Storz @Ede_123

    I agree to your opinion to some extent. At the same time we got multiple reports from people who complained about those characters not being usable directly.

    The issue of double escaping "\\&" does not bug me.
    The issue of not being able to use a plain "&" is a problem however as it prevents some valid use cases as in your initial report.

    Would you mind filing a report at https://inkscape.org/report about the issue of not being able to use plain "&"?

    I still need to think about how to address this best:

    • I agree PDF-LaTeX-Export is not WYSIWYG (because LaTeX renders the text and not Inkscape.
    • I disagree it should not aim to be WYSIWYM (i.e. if a user enters "100%" I expect LaTeX to render this literally, so the percent needs to be escaped.
    • Possibly it needs to be an option ("Automatically escape LaTeX control characters" or similar), so most users can just use it, while advanced use cases are still possible)
  5. #5
    mvscheven mvscheven @mvscheven

    I have created an issue: https://gitlab.com/inkscape/inbox/-/issues/4873

    Ede_123

    I agree to your opinion to some extent. At the same time we got multiple reports from people who complained about those characters not being usable directly.

    Maybe I am a little to strict about this, but if these people use the ampersand or percent sign in the caption of the Inkscape graphic, they need to escape it themselves. This is LaTeX.

    If control characters are escaped automatically by the export (always or controlled by an option) this should not be limited to two of them. In some parts of the world the dollar sign is probably also often used literally, so it could also be escaped automatically. But on the other hand, the dollar sign as a math delimiter is very often also used as a control character.

    Introducing an option for this would be a very elegant solution, also avoiding further discussions about a consistent and transparent behaviour of the export. But for us this would of course solve our problem!

    I looked into the source code and noticed that in LaTeXTextRenderer::sp_flowtext_render() the ampersand and percent sign are not escaped. Is this on purpose?

  6. #6
    Patrick Storz Patrick Storz @Ede_123

    > I looked into the source code and noticed that in LaTeXTextRenderer::sp_flowtext_render() the ampersand and percent sign are not escaped. Is this on purpose?

    "flowtext" has been replaced in Inkscape by SVG2 text.

    There's not much point in maintaining the flowtext option at this point and it will likely be removed altogether at some point.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Using Matrices in PDF-LaTeX Export