yishn / tikzcd-editor

A simple visual editor for creating commutative diagrams.

Home Page:https://tikzcd.yichuanshen.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Could not match edge label" error when copying code

MMF2 opened this issue · comments

commented

When copying the code of a diagram (opening it with the "{ }"-button) and pasting it into another instance of the application I sometimes get an error message "Could not parse code. Reason: Could not match edge label."
An example of such code is the following:

\begin{tikzcd}
A \arrow[d, "\overline{g}"'] &  & A\times B \arrow[rrdd, "g"] \arrow[rr, "\pi_2"] \arrow[ll, "\pi_1"'] \arrow[dd, "\overline{g}\times\mathbf{1}_B" description, dashed] &  & B \arrow[d, "\mathbf{1}_B"] \\
C^B                          &  &                                                                                                                                       &  & B                           \\
                             &  & C^B\times B \arrow[llu, "\pi'_1"] \arrow[rru, "\pi'_2"'] \arrow[rr, "{\mathrm{ev}_{B,C}}"']                                           &  & C                          
\end{tikzcd}

@zickgraf Can you please take a look at this?

Here's the permalink to the given diagram for debugging purposes.

I just tried to create a minimal example and even the most basic example currently throws an error for me:

\begin{tikzcd}
A \arrow[r] & B
\end{tikzcd}

throws the error

Could not parse code.

Reason: i is not defined

Could this be related to recent changes? Tomorrow I will investigate further.

Edit: the error i is not defined probably arises from this: 6ae5302#r36923167

I now have a minimal example and an explanation:

\begin{tikzcd}
A \arrow[r, "{,}"] & B
\end{tikzcd}

The parser splits the arrow definition at ,, even if the comma is inside the label. The same holds for ]. I'm currently not sure how to fix this in a way which does not cause other problems. I will think about this.

Yeah... it's difficult to parse tikzcd syntax correctly without parsing the entirety of LaTeX.

Maybe we can start at the first "{ after the direction directives, iterate over the characters, and use a counter to count up at { or count down at }. We know that the label ends with a " if the counter is 0. Only after we're sure we have the label, can we split at ] for the remaining arrow arguments.

This way, we need to make sure not to count \} and all of these edge cases:

\arrow[r, "{\}}"]
\arrow[r, "{\\}"]
\arrow[r, "{\\\}}"]

I would like to avoid having to deal with all the edge cases when escaping stuff. Thus, I have a different suggestion:

If we know where the arrow definition ends (i.e., can find the correct ]), it is easy to match the label by just matching "{.*}" or ".*". Finding the correct ] is also easy as long as the user does not use ] in the label. Luckily, there is \rbrack as a replacement. So I suggest to declare the usage of ] in the label as unsupported and advise users to use \rbrack instead. I will open a PR implementing this any minute.

PS: Sorry for the late reply :(

@zickgraf Don't worry about it, thanks for the pull request!