While writing software documentation, the need arose for a command that automatically hyphenates camelCase words at uppercase letters, e.g. camel-Case. Furthermore, these camelCase words are typeset to a certain color. The solution was provided here via a command \zzz{camelCase}.
However, some of the camelCase variables are documented for internal use only. To this end there is a flag defined as
\newboolean{\internal}
\setboolean{internal}{true}
in a config file. For example if a whole paragraph is for internal use only, one can write
\ifthenelse{\boolean{internal}}{%
Here is a paragraph which will only appear when the \textbackslash internal flag is set to TRUE.%
}{}%
But this is not a practical implementation for all internal camelCase variables. It would be a pain to write and even worse for source code readability. It would be far better to define a command that contains the functionality of \zzz but also reacts to the internal flag. More precisely, the desired behaviour of a new command \zzzconditional{camelCase} would be:
- iternal flag TRUE: input argument camelCase is hyphenated at capitals and formatted according definition in
\zzz{camelCase} - internal flag FALSE: input argument camelCase disappears entirely from final document. Bonus points if preceding space is removed so that missing camelCases do not leave blanks in document.
So I tried the following:
\newcommand{\zzzconditional}[1]{%
\ifthenelse{\boolean{internal}}{%
\zzz{#1}%
}{}%
}
I can now switch internal variables on and off in the document by writing them as \zzzconditional{camelCase}. But this breaks the hyphenation functionality of the \zzz command and causes overfull lines - i.e. I'm back to where I started before I had \zzz.
Is there any way of "expanding" my command \zzzconditional so that \zzz on the inside works? I hope "expanding" is the right term in latex slang. Bonus points for a solution that also removes the preceding space along with the camelCase variable in my text.
If a solution would be too painstaking to implement please let me know as I do not wish to impose. I have a Plan B: scanning my latex source with Python for the use of \zzz{} and removing the relevant source code. However, non-Pythonistas will also have to work with this document so native latex solutions are preferable.
I have modified the MWE from the previous solution to provide an example of all mentioned commands:
\documentclass{scrartcl}
\usepackage{xcolor}
\usepackage{ifthen}
\showhyphens{createUnspecifiedNodeErrorMarker}
\def\zzcolor{\color{red}}
% --------------------------------------------
% Definition of \zzz
% --------------------------------------------
\makeatletter
\def\zzz{\leavevmode\begingroup
\def\zzelt##1{%
\catcode`##1\active\uccode`\~`##1\uppercase{%
\def~{\egroup\egroup\-\hbox\bgroup\bgroup\zzcolor\string##1}}}%
\zz@Alph{}%
\@zzz}
\def\zz@Alph#1{%
\zzelt A\zzelt B\zzelt C\zzelt D\zzelt E\zzelt F\zzelt G\zzelt H\zzelt I\zzelt J\zzelt
K\zzelt L\zzelt M\zzelt N\zzelt O\zzelt P\zzelt Q\zzelt R\zzelt S\zzelt T\zzelt U\zzelt V\zzelt W\zzelt X\zzelt
Y\zzelt Z}
\def\@zzz#1{\textbf{\hbox\bgroup\bgroup\zzcolor#1\egroup\egroup}\endgroup}
\makeatother
% --------------------------------------------
% Flag to set internal version of document
% --------------------------------------------
\newboolean{internal}
\setboolean{internal}{true}
% --------------------------------------------
% Definition of \zzzconditional which should work like \zzz, but only print to document if interal flag is TRUE
% --------------------------------------------
\newcommand{\zzzconditional}[1]{%
\ifthenelse{\boolean{internal}}{%
\zzz{#1}%
}{}%
}
\begin{document}
\section{Test}
Here is an example of how \textbackslash zzz\{\} hyphenates camelCase words. This may also create overfull lines, but I can live with the result because the overflow is minimal and variables in the real document have more capitals than the one in this MWE:
And another example the show must go on, but we have too less text (\zzz{createUnspecifiedNodeWarningMarker} and
\zzz{createUnspecifiedNodeErrorMarker}, sdjklashjksa \zzz{createUnspecifiedLinkWarningMarker} and
\zzz{createUnspecifiedLinkErrorMarker}).
\ifthenelse{\boolean{internal}}{%
Here is a paragraph which will only appear when the \textbackslash internal flag is set to TRUE. This is very helpful if I only want it to appear in the internal version of this example document. The next paragraph is visible in source code only because I change internal flag's value to FALSE.%
}{}%
\setboolean{internal}{false}
\ifthenelse{\boolean{internal}}{%
Now the internal flag has been set to FALSE which makes this paragraph disappear. This is very helpful if I only want it to appear in the internal version of this example document.%
}{}%
\setboolean{internal}{true}
Here is an example of an overfull line because wrapping \textbackslash zzz\{\} inside \textbackslash zzzconditional\{\} does not work properly, as illustrated by this very long variable \zzzconditional{createUnspecifiedNodeWarningMarker}.
\end{document}



\expandafterbut could not get a version of\zzzconditional{camelCase}that removes input argument if internal flag is FALSE. Do you have any ideas? – Jay_At_Play Apr 05 '18 at 07:08\expandaftermay actually be unnecessary (it is in this particular example and I am not full cognizant of how\ifthenelsehandles its two cases). – Steven B. Segletes Apr 05 '18 at 09:51\expandafteris not needed, so I will remove it from my answer. – Steven B. Segletes Apr 05 '18 at 10:01\expandafter. In the real document (i.e. not the MWE) I discovered one very minor bug. If a paragraph starts with\zzzconditional{camelCase}while internal flag is FALSE, there is an error: "You can't use\unskipin vertical mode". This only occurred once and is easily fixed by rewriting that paragraph. So just FYI, no bugfix needed. Thank you very much again for your help! Will pass knowledge "downhill" and contribute here. – Jay_At_Play Apr 05 '18 at 12:15\leavevmode\unskip. That should work at the beginning of a paragraph. – Steven B. Segletes Apr 05 '18 at 16:36