1

as the title says, I have a problem with babel and the label of the angle ("A") in my figure. If remove the line of \usepackage[spanish]{babel} or don't lable the angle, all compile without problems. But I can't use both. I have read in the beamer user manual that ">" symbol may cause problems, and have read several similar problems here in SE, but not one helps with my specific problem.

thanks in advance for any guide to a possible solution. Here a part of the code:

\documentclass[10pt,Spanish]{beamer}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\begin{document}

\begin{frame}{TIKZ}
\begin{tikzpicture}[>=latex]
            \begin{axis}[
            axis lines = middle,
            axis equal,
            width=0.9\textwidth,
            height=0.7\paperheight,
            xlabel = $x$,
            ylabel = $y$,
            xmin = -5, xmax=5,
            ymin = -5, ymax=5,
            xtick = {0},
            ytick = {0}
            ]
            \addplot[->, very thick, red] coordinates{(0,0)(2,3)} node[midway, left]{$\vec{F}_1$};
            \coordinate (A) at (axis cs:2,0);
            \coordinate (B) at (axis cs:0,0);
            \coordinate (C) at (axis cs:2,3);
            \pic[draw, ->, "A", angle radius = 0.8cm]{angle = A--B--C};
            \end{axis}
    \end{tikzpicture}
\end{frame}
\end{document}
7
  • 1
    Welcome to TeX.SX! I have not tested it, but could you try to add TikZs babel library as well and see, if this helps? Commented May 7, 2021 at 6:50
  • Thank You for your comment @StefanPinnow, I have tried the option babel in \usetikzlibrary, it doesn't work. Commented May 7, 2021 at 12:34
  • You could try \usepackage[shorthands=off,spanish]{babel} to see if it makes a difference. Also the Spanish option for \documentclass{beamer} is probably not needed so that can be removed.
    – Marijn
    Commented May 7, 2021 at 13:45
  • Thank You very much @Marijn, that works! Commented May 7, 2021 at 15:06
  • 1
    @StefanPinnow actually I tried to find a duplicate for shorthands=off but the information is rather scattered across related questions and comments, talking about \shorthandoff{} and usetikzlibrary{babel}. So I guess it wouldn't be a bad idea to collect the information in an answer here, I'll write it when I have time (somewhere in the next few days hopefully).
    – Marijn
    Commented May 10, 2021 at 19:15

1 Answer 1

2

The babel package defines shorthand characters for a number of languages. A shorthand is a character or character combination that makes it easy to enter language-specific punctuation or disable ligatures. The following code shows the use of shorthands for Spanish and the output of the same code for English, where shorthands are not active:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[english,spanish]{babel}
\begin{document}
Spanish shorthands are "<characters"> with a special-meaning defined by "`babel"' that can be switched off and on and of"-f again.

\begin{otherlanguage}{english}
Spanish shorthands are "<characters"> with a special-meaning defined by "`babel"' that can be switched off and on and of"-f again.
\end{otherlanguage}
\end{document}

enter image description here

For Spanish the following shorthands are defined (see the babel package manual section 1.10 "Shorthands" with a list for all languages on page 14):

" . < > ' ~

To implement the shorthand functionality these characters are made active, i.e., turned into macros. If the characters are used in TikZ code, or in other places where they are expected to have a normal meaning as regular characters, then the code will break. The combination of TikZ with French is notorious for this, because French defines ; as a shorthand and this character is used very frequenty in TikZ. But for Spanish you can also run into trouble with " and > as in the example in this question.

You can switch off the shorthands using the babel package option shorthands=off.

MWE:

\documentclass[10pt]{beamer}
\usepackage[T1]{fontenc}
\usepackage[shorthands=off,spanish]{babel}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\begin{document}

\begin{frame}{TIKZ}
\begin{tikzpicture}[>=latex]
            \begin{axis}[
            axis lines = middle,
            axis equal,
            width=0.9\textwidth,
            height=0.7\paperheight,
            xlabel = $x$,
            ylabel = $y$,
            xmin = -5, xmax=5,
            ymin = -5, ymax=5,
            xtick = {0},
            ytick = {0}
            ]
            \addplot[->, very thick, red] coordinates{(0,0)(2,3)} node[midway, left]{$\vec{F}_1$};
            \coordinate (A) at (axis cs:2,0);
            \coordinate (B) at (axis cs:0,0);
            \coordinate (C) at (axis cs:2,3);
            \pic[draw, ->, "A", angle radius = 0.8cm]{angle = A--B--C};
            \end{axis}
    \end{tikzpicture}
\end{frame}
\end{document}

Result:

enter image description here

3
  • 1
    Great answer!!! Commented Sep 22, 2022 at 8:39
  • @samcarter I did the other one from your comment yesterday as well.
    – Marijn
    Commented Sep 22, 2022 at 8:44
  • Great! The missing language key seems like such a tiny problem, but it is hard to find amongst all these options, so the answer might be very useful for many people Commented Sep 22, 2022 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .