2

Please see attached mwe. How can we optionally protect characters or words from the effect of \MakeLowercase{}?

\documentclass{article}%

\def\thestring{A Pacific hurricane is a mature tropical cyclone that develops within the northeastern and central {P}acific {O}cean}

\begin{document}

\noindent\thestring.\

{\noindent}The expedition leader explained that \MakeLowercase{\thestring}.

\end{document}

Skillmon
  • 60,462

1 Answers1

2

You can use the features of \text_lowercase:n of expl3:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn \NewDocumentCommand{\Lower}{m} { \group_begin: \tl_put_right:Nn \l_text_case_exclude_arg_tl { \K } \text_lowercase:n { #1 } \group_end: } \NewDocumentCommand{\K}{m}{#1} \ExplSyntaxOff

\newcommand\teststring{A Pacific hurricane is a mature tropical cyclone that develops within the northeastern and central \K{Pacific Ocean}}

\begin{document}

\teststring.

The expedition leader explained that \Lower{\teststring}.

\end{document}

By itself \K does nothing else than deliver its argument, but it will do so only after \text_lowercase:n has done its job; adding \K to the list of excluded commands, does the trick.

The operation

\tl_put_right:Nn \l_text_case_exclude_arg_tl { \K }

could be also done once and for all:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn \NewDocumentCommand{\Lower}{m} { \text_lowercase:n { #1 } } \NewDocumentCommand{\K}{m}{#1} \tl_put_right:Nn \l_text_case_exclude_arg_tl { \K } \ExplSyntaxOff

You could also use K{P}acific \K{O}cean.

egreg
  • 1,121,712