I am using the Dia graphics editor and exporting my diagrams to TikZ code. I am trying to address Dia's inability to easily typeset formulas e.t.c. by using LaTeX for this part. Unfortunately that editor does not (and will not) allow raw text to be exported directly - any LaTeX code inserted in e.g. a text label is escaped in the output, which makes it (mostly) useless:

\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
% setfont left to latex
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\node at (4.000000\du,6.000000\du){PlaceHolder0};
% setfont left to latex
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\node at (4.000000\du,8.000000\du){PlaceHolder1};
% setfont left to latex
\definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
\node at (4.000000\du,10.000000\du){!@\#\$\%\^{}\&*()|\{\}\ensuremath{[}\ensuremath{]}<>};

The code above corresponds to a diagram with three text labels. The line before the last one is a label with a bunch of symbols: !@#$%^&*()|{}[]<> becomes !@\#\$\%\^{}\&*()|\{\}\ensuremath{[}\ensuremath{]}<>. Not every symbol is escaped, but quite a few of them are.

I was hoping to get around this limitation, using the catchfile package to "import" the TikZ code and then StrSubstitute from the xstring package to replace specific placeholder text with raw TeX code. My current code looks like this:


Unfortunately it does not seem to work - LaTeX runs for an inordinate amount of time at 100% CPU and then the output still has the original text.

How can I make this work? Alternatively, is there another way to do this that does not involve external programs?

  • How is latex code escaped in the output? E.g. what happens when you add \mytext in a label? And what would happen with |mytext or §mytext? Jan 5, 2015 at 9:50
  • 1
    Can you add a simple example of a file that you want to import and of a typical replacement?
    – egreg
    Jan 5, 2015 at 10:34
  • @UlrikeFischer: \mytext becomes \\mytext. Same with all "special" characters...
    – thkala
    Jan 5, 2015 at 15:54
  • And what about |? If this is stable you could use it instead of the backslash. Jan 5, 2015 at 16:01
  • @egreg: I posted a sample file with three text labels, including one with symbols.
    – thkala
    Jan 6, 2015 at 16:48

1 Answer 1


A bit long for a comment. You could write in the label a command as |mytext and in the tex document locally change the catcode of | so that it can be use instead of the backslash:


(This naturally will only work if | is not used somewhere else in your tikz code.)

  • Excellent! This does indeed work very nicely...
    – thkala
    Jan 7, 2015 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.