# Problem with linebreak in combination with strikeout from the ulem package and newcommand

Is it possible to combine the "result" of a newcommand with the sout command of the ulem package with working linebrak/hyphenation?

\documentclass{article}
\usepackage{ulem,lipsum}
\textwidth=3cm % just to force hyphenation/linebreaks to happen
\usepackage[T1]{fontenc}
\begin{document}
\sout{The sout makro of ulem is able to handle hyphenation and linebreaks in text entered directly but not as macro see next line!}
\sout{\lipsum[1]}
\newcommand\test{Nore does it work with a simple macro text.}
\sout{\test}
\end{document}


The code above produces the following output.

as TeXnician suggested in the simplest form it works like this:

\newcommand\souttest{\expandafter\sout\expandafter{\test}}
\souttest


I've tried to implement this to my situation which ist slightly more complicated. I have a Lyx "local Format" defined to highlight text and to make annotations to have a convenient way to do QCAmap and reduce ERT in Lyx! So the simply version of the Problem is:

\expandafter\newcommand\csname soutAutoP\endcsname{\expandafter\sout\expandafter{\csname test\endcsname}}
\soutAutoP


For those interested the long version it is as follows:

InsetLayout Flex:Kategorie
LyxType               charstyle
LabelString           kategorie
LatexType             command
LatexName             kategorie
Argument 1
Decoration conglomerate
LabelString    "Name"
Tooltip        "Eindeutiger Kategorie Name"
Mandatory 1
EndArgument
Argument 2
LabelString    "Phra"
Tooltip        "Text der Phrase"
Mandatory 1
EndArgument
Argument 3
LabelString    "Gen"
Tooltip        "Text der Generalisierung"
Mandatory 1
EndArgument
Preamble
\usepackage{ifthen}
\usepackage[dvipsnames]{xcolor}
\newcommand{\KatFarbe}[1]
{
\ifthenelse{\equal{#1}{A}}{\colorlet{myColor}{blue}}{%
\ifthenelse{\equal{#1}{B}}{\colorlet{myColor}{lime}}{%
\ifthenelse{\equal{#1}{C}}{\colorlet{myColor}{orange}}{%
\ifthenelse{\equal{#1}{D}}{\colorlet{myColor}{cyan}}{%
\ifthenelse{\equal{#1}{E}}{\colorlet{myColor}{purple}}{%
\ifthenelse{\equal{#1}{F}}{\colorlet{myColor}{red}}{%
\ifthenelse{\equal{#1}{G}}{\colorlet{myColor}{magenta}}.{\colorlet{myColor}{gray}}}}}}}}
}
\usepackage{xstring}
\usepackage{tikz}
\usepackage[normalem]{ulem}
\newcommand\encircle[1]{%
\tikz[baseline=(X.base)]
\node (X) [draw, shape=circle, inner sep=0] {\strut #1};}
\newcommand{\kategorie}[4]{%
\expandafter\gnewcommand\csname Kat#1\endcsname{\hspace{0pt}#4}%
\expandafter\gnewcommand\csname Kat#1P\endcsname{\hspace{0pt}#2}%
\expandafter\gnewcommand\csname soutKat#1P\endcsname{\expandafter\sout\expandafter{\csname Kat#1P\endcsname}}%
\expandafter\gnewcommand\csname Kat#1G\endcsname{\hspace{0pt}#3}%
\StrLeft{#1}{1}[\myKat]\KatFarbe{\myKat}\linelabel{lne:#1}\linelabel{lne:#1Start}\textcolor{myColor!80!black}{\expandafter\csname Kat#1\endcsname$^{\tiny\encircle{\myKat}}$}\linelabel{lne:#1Stop}}
EndPreamble
End


With this code you get a new Command in Lyx like this:

You get an output like this:

To access the reduced text with the sout one can write:

\expandafter\sout\expandafter{\KatCSexEtwP}
%to reduce the ERT I tried to combine it to
\soutKatCSexVsKoerperP


But I failed. As for the question of TeXnician I honestly don't know because I'm not that deep in TeX. Sorry!

Sorry for the German in the code.

It's easy for a simple new command as in your example, just add \expandafter (which won't work for \lipsum btw):

\documentclass{article}
\usepackage{ulem,lipsum}
\textwidth=3cm % just to force hyphenation/linebreaks to happen
\usepackage[T1]{fontenc}
\begin{document}
\sout{The sout makro of ulem is able to handle hyphenation and linebreaks in text entered directly but not as macro see next line!}
\sout{\lipsum[1]}
\newcommand\test{Nore does it work with a simple macro text.}
\expandafter\sout\expandafter{\test}
\end{document}

• Is there a common solution for more complicated macros like lipsum? – Andreas Oberreiter May 6 '18 at 14:37
• I tried to implement your solution to my "real" problem which is in it's simplest form like this: \expandafter\newcommand\csname soutAutoP\endcsname{\expandafter\sout\expandafter{\csname test\endcsname}} but in this case the solution doesn't work. – Andreas Oberreiter May 6 '18 at 16:34
• @AndreasOberreiter How is your command defined (the test one)? Is it expandable (it will only work with expandable commands)? – TeXnician May 6 '18 at 18:11