4

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:
  }

\tl_new:N \g_metadata_title_tl

\NewDocumentCommand \mytext {m}
  {
    \tl_gset:Nn \g_metadata_title_tl {#1}
  }

\NewDocumentCommand \thetext {}
  {
    \tl_use:N \g_metadata_title_tl
  }

\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
4

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:
  }

\tl_new:N \g_metadata_title_tl

\NewDocumentCommand \mytext {m}
  {
    \tl_gset:Nn \g_metadata_title_tl {#1}
  }

\DeclareExpandableDocumentCommand \thetext {}
  {
    \tl_use:N \g_metadata_title_tl
  }

\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}
|improve this answer|||||
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.