# expl3: lowercase a token list inside a tikz node

This question ask for a variant of the answer to expl3: lowercase a token list given by Joseph Wright

I want to convert to lowercase a token list that is composed by letter, digits and the control sequence \\ . The method used by Joseph Wright (which is to make robust \\) works fine in normal text, but fails with a compilation error when used inside a TikZ node.

\documentclass{article}

\usepackage{xparse}
\usepackage{tikz}

\ExplSyntaxOn
\NewDocumentCommand \LowerCase { m }
{
\group_begin:
\cs_set_protected:Npx \\ { \exp_not:o \\ }
\tl_lower_case:n {#1}
\group_end:
}

\NewDocumentCommand \mytext {m}
{
}

\NewDocumentCommand \thetext {}
{
}

\ExplSyntaxOff

\begin{document}
\mytext{This is my\\ Text}

\noindent\LowerCase{\thetext}

\begin{tikzpicture}[overlay, remember picture]
\node[align=left] (text1) {\thetext};

\node[align=left, below of = text1] (text2) {\LowerCase{\thetext}};
\end{tikzpicture}

\end{document}


Note: The text to lowercase is should be taken from a token list variable.

• @JosephWright Sorry Guys! I had multiple test line before writong the question and overlooked that the text wasn't lowercased. By the way, I thought that the expl3 functions are expandable if not noted explicity the contrary. – TeXtnik Sep 8 '16 at 5:53
• @TeXtnik expl3 ones yes, but xparse ones no. If you define with \NewDocumentCommand you get a protected macro. – Manuel Sep 8 '16 at 8:56

The issue here that you can't have \begingroup ... \endgroup around the content of the node if it's aligned: this can be seen with a simple example

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node[align=left] {\begingroup Hello\\World\endgroup};
\end{tikzpicture}
\end{document}


Thus we need to save and restore the meaning of \\ without a group. Assuming no nesting is required:

\documentclass{article}

\usepackage{xparse}
\usepackage{tikz}

\ExplSyntaxOn
\NewDocumentCommand \LowerCase { m }
{
\cs_set_eq:NN \__texnik_newline: \\
\cs_set_protected:Npx \\ { \exp_not:o \\ }
\tl_lower_case:n {#1}
\cs_set_eq:NN \\ \__texnik_newline:
}

\NewDocumentCommand \mytext {m}
{
}

\DeclareExpandableDocumentCommand \thetext {}
{
}

\ExplSyntaxOff

\begin{document}
\mytext{This is my\\ Text}

\noindent\LowerCase{\thetext}

\begin{tikzpicture}[overlay, remember picture]
\node[align=left] (text1) {\thetext};

\node[align=left, below of = text1] (text2) {\LowerCase{\thetext}};
\end{tikzpicture}

\end{document}

• In case it matters, align key switches the node text to be inserted inside a minipage environment instead of an \hbox. – percusse Sep 8 '16 at 9:17
• @percusse There's more to the issue than that, as you can put a group inside a minipage (which is a \vbox after all). – Joseph Wright Sep 8 '16 at 9:19
• Oh yes, I had once read that part. It's not fun. – percusse Sep 8 '16 at 9:20
• @JosephWright It is working fine within my application. What do you mean with "Assuming no nesting is required"? I don't intend to use \LowerCase{\LowerCase{\thetext}} – TeXtnik Sep 8 '16 at 14:27