Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dot2tex "eats" escaped backslashes from labels in raw mode #106

Open
Britaliope opened this issue Nov 7, 2023 · 4 comments
Open

dot2tex "eats" escaped backslashes from labels in raw mode #106

Britaliope opened this issue Nov 7, 2023 · 4 comments

Comments

@Britaliope
Copy link

Britaliope commented Nov 7, 2023

With the input dot file:

digraph test {
100 -> 102 [label="Test raw \\latex output \\textit{italic text}"];
}

compiled with dot2tex --texmode raw --format tikz test.dot

the tikz draw command for the label is

  \draw (176.04bp,62.625bp) node {Test raw latex output textit{italic text}};

while the expected result according to the documentation is

  \draw (176.04bp,62.625bp) node {Test raw \latex output \textit{italic text}};

I've tried to escape 1, 2, 3, 4 times the backslash but it still produce result without any backslalshes.

Surprisingly, when adding --tikzedgenodes option, the backslashes are escaped correctly.

@Britaliope
Copy link
Author

Britaliope commented Nov 7, 2023

I am trying to understand the code behind this to debug it, especially the parse_drawstring and the do_drawstring functions, but i am a bit lost and not understanding everything. I'd like to submit a fix for this but any educated guess on where to look and/or what to investigate would help me here

@kjellmf
Copy link
Collaborator

kjellmf commented Nov 12, 2023

I'm sorry, but I have not touched this project for years and I must admit that I hardly remember how the code works. If you find a fix I'll be happy to merge it in.

@Rafaeltheraven
Copy link

Rafaeltheraven commented Apr 12, 2024

Just ran into this as well. The issue only happens for edge labels, node labels are properly inserted raw.

:edit: seems to happen in math mode as well. There's a fundamental issue with latex inside of edge labels.
:edit2: This does not seem to happen on the development version (it does happen on the one in the Arch repo). Now it's just printing the edge labels twice...

@Rafaeltheraven
Copy link

Did some investigation and I've found the cause of both problems (eating backslashes and duplicate labels).

  1. The reason why labels on vertices aren't affected is because drawing of edges works differently from vertices. The issue only occurs on edges.
  2. dot2tex converts the dot format to xdot using Graphviz's dot program. xdot does some parsing. This is the cause of my duplicate label issue. I was using $\rightarrow$ which includes \r and was thus treated as a newline, creating 2 T jobs. In the text drawing method, we go through all the jobs and, if it's a T job, just takes whatever text was stored in label and uses that instead. We have 2 T jobs, thus 2 labels.
  3. In doText, we remove all backslashes (
    s = drawstring.strip().replace('\\', '')
    ). If we thus use 2 backslashes so we can escape stuff for the xdot conversion, it comes back to us with the backslashes removed, breaking the Latex (unless we use the newer version of the library, which uses the approach describe in point 2).

I'm not making a PR yet because I'm not sure what the best approach is here. For now, my fork simply removes the bit about taking what's stored in the label and only collapses double backslash into single backslash. This works for my specific case, but may not be a universally working solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants