reutenauer / polyglossia

An alternative to Babel for XeLaTeX and LuaLaTeX
http://www.ctan.org/pkg/polyglossia
MIT License
187 stars 52 forks source link

german and tikz-cd incompatibility #95

Closed stev47 closed 4 years ago

stev47 commented 9 years ago

I'm compiling

\documentclass{standalone}

\usepackage{tikz}
\usepackage{tikz-cd}
\usepackage{polyglossia}
\setmainlanguage{german}

\begin{document}

\begin{tikzcd}
    a \ar[r,"c"] & b
\end{tikzcd}

\end{document}

and getting the error

! Package pgfkeys Error: I do not know the key '/tikz/"c"' and I am going to ig
nore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help
...
l.11 I think the culprit is a tikzcd arrow in cell 1-1.
\errmessage ...currentrow -\tikzcd@currentcolumn }

l.12 \end{tikzcd}

Note that changing \setmainlanguage{german} to \setmainlanguage{english} works. The line \initiate@active@char{"}% in tex/gloss-german.ldf seems to be the culprit: uncommenting it solves the problem.

Note that this happens regardless of the babelshorthands options and even setting \bbl@deactivate{"} manually afterwards doesn't work.

jspitz commented 9 years ago

Note that the example file compiles if you load \usetikzlibrary{babel} before loading tikzcd (as advised in section 3.4 of the tikzcd manual).

I am not sure this is a polyglossia bug.

stev47 commented 9 years ago

Thank you for pointing me to the right place, that is indeed a good workaround.

I'd still argue, that polyglossia shouldn't mess around with the catcodes as long as I'm not telling it to do so. Isn't that why the babelshorthands option was introduced in the first place (instead of just adopting babels defaults)?

gnull commented 5 years ago

@jspitz, I'm experiencing a similar issue with Russian language. I can't compile (using xelatex) the following example:

\documentclass[a4paper,12pt]{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{russian}
\setotherlanguage{english}
\setkeys{russian}{babelshorthands=true}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}

% \usepackage{tikz}
% \usetikzlibrary{babel}

\usepackage{tikz-cd}

\begin{document}

\[
\begin{tikzcd}[column sep=small]
X \arrow[r, "f"] & Y
\end{tikzcd}
\]

\end{document}

Neither enabling \usetikzlibrary{babel} nor removing the line \setkeys{russian}{babelshorthands=true} fixes compilation errors. (Although the errors messages themselves change.)

But, if I replace the part

\setmainlanguage{russian}
\setotherlanguage{english}
\setkeys{russian}{babelshorthands=true}

with \setmainlanguage{english} the document compiles perfectly.

Do you have any idea what could cause this problem? (I'm not sure if it is a polyglossia bug.)

jspitz commented 5 years ago

No idea, sorry.

jspitz commented 4 years ago

@gnull, in your case, loading tikzcd before polyglossia helps:

\documentclass[a4paper,12pt]{article}

\usepackage{tikz}
\usetikzlibrary{babel}
\usepackage{tikz-cd}

\usepackage{polyglossia}
\setmainlanguage{russian}
\setotherlanguage{english}
\setkeys{russian}{babelshorthands=true}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}

\begin{document}

    \[
    \begin{tikzcd}[column sep=small]
    X \arrow[r, "f"] & Y
    \end{tikzcd}
    \]

\end{document}
jspitz commented 4 years ago

I had a closer look at this once more. The problem comes from the line

\initiate@active@char{"}%

which we issue in the gloss files that use shorthands. As this command can only be used in the preamble, we need to do it unconditionally, as babel shorthands might be activated only locally in the body, and this does not work without the above activating.

We could do the activation later in the preamble, but this does not help for tikz. So the only solution, as advised in the tikz and tikzcd manuals, is to load the babel tikz library, indeed. This seems to be the same with babel.

Thus, we can only close this report.

wehro commented 4 years ago

Possible solution: Say \shorthandoff{"} and \AtBeginDocument{\shorthandon{"}} in gloss-german.ldf and similar files after \initiate@active@char{"}. This is what I plan to do for the active = in gloss-latin.ldf, because an active = is even more dangerous than an active ".

jspitz commented 4 years ago

Possible solution: Say \shorthandoff{"} and \AtBeginDocument{\shorthandon{"}} in gloss-german.ldf and similar files after \initiate@active@char{"}.

This does not help here either.

eg9 commented 4 years ago

This is similar to #200 Besides loading the babel library, packages should be loaded before doing setup.

\documentclass{standalone}

\usepackage{polyglossia}
\usepackage{tikz}
\usetikzlibrary{babel}
\usepackage{tikz-cd}

\setmainlanguage{german}

\begin{document}

\begin{tikzcd}
    a \ar[r,"c"] & b
\end{tikzcd}

\end{document}
jspitz commented 4 years ago

@gnull, in your case, loading tikzcd before polyglossia helps:

\documentclass[a4paper,12pt]{article}

\usepackage{tikz}
\usetikzlibrary{babel}
\usepackage{tikz-cd}

\usepackage{polyglossia}
\setmainlanguage{russian}
\setotherlanguage{english}
\setkeys{russian}{babelshorthands=true}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}

\begin{document}

  \[
  \begin{tikzcd}[column sep=small]
  X \arrow[r, "f"] & Y
  \end{tikzcd}
  \]

\end{document}

After 0cb40fca6cf6a3e496, this example also works in the original order. But still the babel tikz library is mandatory.

gnull commented 4 years ago

@gnull, in your case, loading tikzcd before polyglossia helps:

\documentclass[a4paper,12pt]{article}

\usepackage{tikz}
\usetikzlibrary{babel}
\usepackage{tikz-cd}

\usepackage{polyglossia}
\setmainlanguage{russian}
\setotherlanguage{english}
\setkeys{russian}{babelshorthands=true}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}

\begin{document}

  \[
  \begin{tikzcd}[column sep=small]
  X \arrow[r, "f"] & Y
  \end{tikzcd}
  \]

\end{document}

@jspitz, thank you for this solution! Yes, I tried it now and it works out of the box on my Archlinux.