TransWikia.com

Node label location taken literally when defining Circuitikz macro with babel french

TeX - LaTeX Asked on April 4, 2021

I’m using the same variant of a circuit multiple times, with only minor changes, so I defined a macro with tikz commands. Here’s my document:

documentclass{article}

usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[french]{babel}
usepackage{siunitx}
usepackage{circuitikz}

usetikzlibrary{babel} % fixes some other bug with tikz and babel french

begin{document}
    newcommandcircuitbase{
        draw (2.5,4) node[label={above:$c$}] {} to[R, a=$SI{2}{kiloohm}$, *-] (2.5,2)
        node[label={left:$a$}] {} to[R, a=$SI{1}{kiloohm}$, *-*] (2.5,0) node[label={below:$d$}] {};
    }

    begin{circuitikz}[american]
        circuitbase
        draw (2.5,2) to[R, l=$SI{470}{ohm}$] (5,2);
    end{circuitikz}
end{document}

However the node labels don’t work correctly when using the macro:

preview

This is most likely due to babel being set to French, because it works with usepackage{babel}. How do I fix it?

2 Answers

(Notice that probably @DanielFlipo answer-in-comment is a better solution --- I hope he'll post an answer; mine below is to just cut the : functionality in babel-french)

This is an interaction between the active chars in babel (I suspect the colon), and it's not circuitikz specific at all. This "more minimal example" also shows the problem:

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[french]{babel}
usepackage{siunitx}
usepackage{tikz}
usetikzlibrary{babel} % fixes some other bug with tikz and babel french

begin{document}
    newcommandcircuitbase{
        draw (2.5,4) node[label={above:$c$}] {} ;
    }

    begin{tikzpicture}[]
        circuitbase
        draw (5,4) node[label={above:$c$}] {} ;
    end{tikzpicture}
end{document}

If you do not need shorthands, the better solution is to use

usepackage[french, shorthands=off]{babel}

and then use the Unicode characters for French letters and accents (although I do not know what : is supposed to do in French, so I can be wrong here).

Answered by Rmano on April 4, 2021

With pdflatex, the colon is made active by babel-french in order to add automatically the space required in French before it (same for ; ! ?). The NoAutoSpacing command is provided for cases where insertion of a space is not wanted.

But adding NoAutoSpacing to the circuitbase command (best in a group) would only remove the spurious space:

newcommandcircuitbase{bgroupNoAutoSpacing
   draw (2.5,4) node[label={above:$c$}] {} to[R, a=$SI{2}{kiloohm}$, *-] (2.5,2)
   node[label={left:$a$}] {} to[R, a=$SI{1}{kiloohm}$, *-*] (2.5,0) node[label={below:$d$}] {};
                        egroup}

I guess that is not what you want. Switching locally to say "english" would not help either (the colon remains active).

Please note that your original command circuitbase works out of the box when compiling with lualatex or xelatex which do not make active high punctuation characters in French.

With pdflatex usetikzlibrary{babel} should fix this issue, but it doesn't.

Answered by Daniel Flipo on April 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP