0

I want to color my text and followed this sample code. Now I have

\documentclass[a4paper,11pt]{article}
\usepackage[a4paper,includeheadfoot,margin=2.54cm]{geometry} % for margins on a A4paper
\usepackage{xcolor} % for highlighting AND background images-color!!!
\usepackage{soul} %for usage of style attributes - background color
\newcommand{\cText}[3][RGB]{%
    \begingroup
    \definecolor{hlcolor}{#1}{#2}\sethlcolor{hlcolor}%
    \hl{#3}%
    \endgroup
}
\definecolor{RGB2}{RGB}{35, 111, 161}
\definecolor{HTML3}{HTML}{bfedd2}
\soulregister\LARGE7
\begin{document}
Test z% translated tag: span
{\cText[HTML]{7e8c8d}
    {wecks U
%       {\LARGE{}msetzung von größeren } % [2] <== not working
%       {\color{HTML3}{}
        {\LARGE{}HTML}
%           Text
%       }-Entities \&<
    }
} 

\end{document}

As soon as I try to uncomment [2] I get the error Package soul Error: Reconstruction failed The same applies for uncommenting the other following lines.

What to do better? Or is there a better approach to color text - especially when the size and background might change?

LeO
  • 1,451
  • 3
    can you use lualatex? Then switch to the lua-ul package - much more robust. – Ulrike Fischer Jun 02 '20 at 14:28
  • Yeah, I am using luatex 1.12. Therefore the question how would a solution look like? To my understanding I need xcolor for changing the text tcolor and soul for highlighting. So I guess that's not a blocking issue to have different colors used. – LeO Jun 02 '20 at 14:47
  • see e.g. https://tex.stackexchange.com/a/533380/2388. Or read the documentation. – Ulrike Fischer Jun 02 '20 at 14:59
  • Sorry for being persistent. But neither the sample referred nor the documentation are quite specific how to define a new highlight color. I see that I can use e.g. red but how to use an own color like a given RGB value? Sounds like the commands are quite different. But perhaps I miss something. – LeO Jun 02 '20 at 15:53
  • 1
    \hl -> \highLight and \sethlcolor -> \LuaULSetHighLightColor (and remove \soulregister\LARGE7). Tada! https://gist.github.com/moewew/af743d98e157a45a7331a1ad926b3787 – moewe Jun 02 '20 at 15:56
  • 3
    Instead of using \LuaULSetHighLightColor you can also use \highLight[{[#1]{#2}}]{#3}. – Marcel Krüger Jun 02 '20 at 15:58

1 Answers1

0

Thx to @moewe and @MarcelKrüger I found the following solution:

\documentclass[a4paper,11pt]{article}
\usepackage[a4paper,includeheadfoot,margin=2.54cm]{geometry} % for margins on a A4paper
\usepackage{xcolor} % for highlighting AND background images-color!!!

\usepackage{luacolor,lua-ul} %for usage of style attributes - background color
\newcommand{\cText}[3][RGB]{%
    \begingroup
    \highLight[{[#1]{#2}}]{#3}%
    \endgroup
}
\definecolor{RGB2}{RGB}{35, 111, 161}
\definecolor{HTML3}{HTML}{bfedd2}

\begin{document}
Test z%
{\cText[HTML]{7e8c8d}
    {wecks U
       {\LARGE{}msetzung von größeren } % [2] <== not working
       {\color{HTML3}{}
           {\LARGE{}HTML}
           Text
       }-Entities \&<
    }
} 

Or simplified: z%
\highLight[{[RGB]{35, 111, 161}}]
    {wecks U
        {\LARGE{}msetzung von größeren } % [2] <== not working
        {\color{HTML3}{}
            {\LARGE{}HTML}
            Text
        }-Entities \&<
    }

Color check after ...

\end{document}

So my conclusion is that the highLight command already has this capability. Unfortunately this is NOT documented in the lua-ul Package description. Perhaps someone could update the docu!

LeO
  • 1,451
  • Both \LuaULSetHighLightColor and the optional argument of \highLight/\hl are documented (explanation at the bottom of p. 1, example at the top of p. 2 in the docs for Lua-UL v0.0.4 [2020/03/31]). What wasn't too clear to me was that it was possible to give the colour scheme as \highLight[{[<scheme>]{<color spec.>}}]. In any case if you want the documentation improved, it is much better to contact the author directly at https://github.com/zauguin/luaul/issues than to mention it in passing in a TeX.SX answer. – moewe Jun 03 '20 at 15:20