0

In the URL removing the first character in a combination of strings and commands/tokens using \gobblechar of stringstrings, @JosephWright has suggested the command \ExplTitlecase (expl3) to capitalize the first word of a set of words set in lowercase.

In the following MWE, I have used Joseph Wright's \ExplTitlecase. I have shown Examples 1 to 4.

%MWE
\documentclass{article}
\newcommand*{\myMixedCaseCommand}[1]{#1}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\ExplTitlecase}{m}
{
\text_titlecase:n { #1 }
}
\ExplSyntaxOff

\begin{document} %Example 1 \ExplTitlecase{first word will be capitalized}

%Example 2 \ExplTitlecase{a certain \uppercase{UPPERCASE} acronym within a set of words set in lowercase}

%Example 3 \ExplTitlecase{a certain \lowercase{lowercase} acronym within a set of words set in lowercase}

%Example 4 \ExplTitlecase{a certain \myMixedCaseCommand{MiXeDCaSe} acronym within a set of words set in lowercase} \end{document}

The MWE compiles fine, and the output in Examples 1 to 3 are expected. However, what I would want for Example 4 is to find some kind of command, which I temporarily call \myMixedCaseCommand, such that this command preserves the mixed-case nature of the acronym MiXeDCaSe. In the output, MiXeDCaSe was lowercased and became mixedcase. I would want the output to be exactly MiXeDCaSe.

Kindly seeking any help.

leandriis
  • 62,593

1 Answers1

1

You can add to the list of commands that should not have their argument acted on by the process.

\documentclass{article}

\NewDocumentCommand{\myMixedCaseCommand}{m}{#1}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\ExplTitlecase}{m} { \text_titlecase:n { #1 } } % add \myMixedCaseCommand to the exclusion list \tl_put_right:Nn \l_text_case_exclude_arg_tl { \myMixedCaseCommand }

\ExplSyntaxOff

\begin{document}

%Example 1 \ExplTitlecase{first word will be capitalized}

%Example 2 \ExplTitlecase{a certain \uppercase{UPPERCASE} acronym within a set of words set in lowercase}

%Example 3 \ExplTitlecase{a certain \lowercase{lowercase} acronym within a set of words set in lowercase}

%Example 4 \ExplTitlecase{a certain \myMixedCaseCommand{MiXeDCaSe} acronym within a set of words set in lowercase}

\end{document}

enter image description here

egreg
  • 1,121,712