3

Responding to this question, David Carlisle provided source code that automatically breaks or hyphenates camelCase words so that they may span multiple lines. Breaking or hyphenation occurs before capitals, e.g. camel-Case.

I have successfully used the code and altered it slightly to match my needs (used typewriter font as well as bold text):

\def\@zzz#1{\textbf{\texttt{\hbox\bgroup#1\egroup}}\endgroup}

However, I cannot colour the text. I have tried various things such as

  • \textcolor inside David Carlisle's implementation, i.e. \def\@zzz#1{\textbf{\texttt{\hbox\bgroup\textcolor{mycustomcolor}{#1}\egroup}}\endgroup}
    I also tried this with \textcolor outside \textbf
  • creating a new command that uses \zzz (David Carlisle wrote this won't work, but I got desperate):
    \newcommand{\coloredcamel}[1]{\textcolor{mycustomcolor}{\zzz{#1}}}
  • and a few other variants. For example, I tried the above with both the color package and the xcolor package. I also tried the \color command.

mycustomcolor was defined using \definecolor{mycustomcolor}{RGB}{201, 20, 15}

Is it somehow possible to colour text in David Carlisle's implementation? Thanks in advance for any help provided.

  • I added color in an answer to the previous question. – egreg Mar 27 '18 at 21:34
  • Thank you @egreg! I upvoted you on the other question, but stuck with the solution posted here (never change a running system =) ) – Jay_At_Play Mar 28 '18 at 10:11
2

You need to use \color not \textcolor also the redefinition of \ifcase to \iftrue was a cheap trick to re-use \Alph to get a list of uppercase letters. It is only safe if no command uses \ifcase in the scope of the envrionment, which is apparently not the case for xcolor so this just defines a new list of uppercase rather than patchng `\@alph, but is otherwise identical code.

\documentclass{scrartcl}
\usepackage{xcolor}
\showhyphens{createUnspecifiedNodeErrorMarker}
\def\zzcolor{\color{red}}
\makeatletter
\def\zzz{\leavevmode\begingroup
\def\zzelt##1{%
  \catcode`##1\active\uccode`\~`##1\uppercase{%
    \def~{\egroup\egroup\penalty2\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

\begin{document}
\section{Test}


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}).
\end{document}

enter image description here

  • Thank you very, very much for your reply. Is it possible to use the xcolor package instead? I tried replacing \usepackage[color] with \usepackage[xcolor] but that causes errors when compiling. I tried to debug or replace \color with \textcolor but my latex knowledge is nowhere near good enough for the kind of "low-level" code in your MWE. Sorry I wasn't clear about my need for xcolor ... I only just realised myself that tikz loads xcolor. – Jay_At_Play Mar 27 '18 at 8:18
  • I tried using xcolor with \color (i.e. only alteration to your MWE was \usepackage[xcolor]) but got several error messages, such as: "Undefined control sequence...", "Missing = inserted...", "Improper alphabetic constant...", "Missing number, treated as zero...", "Improper alphabetic constant..." – Jay_At_Play Mar 27 '18 at 8:34
  • @Jay_At_Play oh yes so you do, sorry! can only require a minor change (xcolor is a compatible extension of color in almost all cases) but out of time now, I'll fix that later and ping you here – David Carlisle Mar 27 '18 at 8:38
  • Thank you so much, you are amazing =) I'll try to pass on the favour and contribute to tex.StackExchange – Jay_At_Play Mar 27 '18 at 8:41
  • @Jay_At_Play xcolor – David Carlisle Mar 27 '18 at 18:44

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.