TransWikia.com

TikZ & library babel - Private macro my@macro unusable with the text of a node

TeX - LaTeX Asked on November 6, 2021

Is there a way to fix the following incompatibility ? I can’t use my private macro for the text of a node.

documentclass{article}

RequirePackage{tikz,amsmath}
usetikzlibrary{babel}

makeatletter
newcommandmy@macro[1]{%
    {tiny$substack{-\#1}$}%
}


newcommandtest[1]{%
    begin{tikzpicture}
        path (0, 0) 
              -- node[draw] {my@macro{#1}}
              (1,0);
    end{tikzpicture}
}
makeatother

begin{document}

test{PARIS}

end{document}

One Answer

REVISED SOLUTION

Thanks to Ulrike, who suggested an alternative to my original solution. I like hers better: avoid the catcode issue with the invocation csname my@macroencsname.

documentclass{article}

RequirePackage{tikz,amsmath}
usetikzlibrary{babel}

makeatletter
newcommandmy@macro[1]{%
    {tiny$substack{-\#1}$}%
}


newcommandtest[1]{%
    begin{tikzpicture}
        path (0, 0) 
              -- node[draw] {csname my@macroendcsname{#1}}
              (1,0);
    end{tikzpicture}
}
makeatother

begin{document}
test{PARIS}
end{document}

enter image description here

ORIGINAL SOLUTION

Not sure why it is needed, but by placing a makeatletter...makeatother wrapper around the embedded invocation, it can be made to work.

documentclass{article}

RequirePackage{tikz,amsmath}
usetikzlibrary{babel}

makeatletter
newcommandmy@macro[1]{%
    {tiny$substack{-\#1}$}%
}


newcommandtest[1]{makeatlettertestaux{#1}makeatother}
newcommandtestaux[1]{%
    begin{tikzpicture}
        path (0, 0) 
              -- node[draw] {my@macro{#1}}
              (1,0);
    end{tikzpicture}
}
makeatother

begin{document}
test{PARIS}
end{document}

Answered by Steven B. Segletes on November 6, 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