latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
124 stars 34 forks source link

Beamer french + beamer + tikz label + +b environment = booom #239

Closed tobiasBora closed 1 year ago

tobiasBora commented 1 year ago

I can’t use the label syntax label={45:my text} to put a label at 45 degrees when beamer + babel french are enabled. I tried various stuff like [fragile], \usetikzlibrary{babel} or \AtBeginEnvironment{tikzpicture}{\shorthandoff{;}\shorthandoff{:}}, none of them work:

I have enter image description here instead of enter image description here

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\usetikzlibrary{babel} % Important, or I get issues on other code when using french babel like "! Package tikz

\NewDocumentEnvironment{mytest}{+b}{
  #1 % I do want to use +b as in practice I do more involved stuff here, involving recursion etc…
}{}
\begin{document}

\begin{frame}[fragile]
  \begin{mytest}
    \begin{tikzpicture}
      \node[label={45:mylabel},fill=green]{AAA};
    \end{tikzpicture}
  \end{mytest}
\end{frame}

\end{document}
PhelypeOleinik commented 1 year ago

I haven't tried, but my bet is you get the same issue without beamer:

\documentclass{article}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{babel}
\NewDocumentEnvironment{mytest}{+b}{#1}{}
\begin{document}

\begin{mytest}
\begin{tikzpicture}
  \node[label={45:mylabel},fill=green]{AAA};
\end{tikzpicture}
\end{mytest}

\end{document}

It won't work because when mytest grabs the contents of the environment, it will tokenize : as the french-babel active colon, rather than a regular catcode-12 colon. It should work if you do (mytest inside tikzpicture):

\begin{tikzpicture}
\begin{mytest}
  \node[label={45:mylabel},fill=green]{AAA};
\end{mytest}
\end{tikzpicture}

or if you use a different way to grab the environment (which will depend on what exactly you are trying to do).

In any case, this is expected behaviour.

tobiasBora commented 1 year ago

Ok thanks. I asked for solutions here and they provided nice alternatives.