Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The following MWE gives a compilation error. If i move the \arabic{count} outside from the \ul command, it works

\documentclass{article}
\usepackage{soul}
\begin{document}

\newcounter{count}%
\setul{0.5ex}{0.3ex}%
\ul{text \arabic{count}}

\end{document}
share|improve this question
    
Use \thecount? :) But, above all, avoid underlining. –  egreg Jan 25 '12 at 9:40
add comment

4 Answers

It works if you define a macro for \arabic{count} and use that:

\documentclass{article}
\usepackage{soul}
\newcommand{\arabcount}{\arabic{count}}
\begin{document}
\newcounter{count}%
\setul{0.5ex}{0.3ex}%
\ul{text \arabcount}
\end{document}

arabic counter underlined with soul

Often it helps, to register a command for soul by

\soulregister{command name}{number of arguments}

so it won't be analyzed by soul but executed. But in this case for \arabic it still gives an error, so I suggest the macro solution.

share|improve this answer
    
I consider the first variant with \arabcount better anyways. –  tohecz Jan 25 '12 at 9:57
add comment

Slightly different from the solution by Stefan, also using a macro and possibly saving a bit of typing. We define a macro \ull to replace \ul

\documentclass{article}
\usepackage{soul}
\begin{document}

\newcounter{count}%
\setul{0.5ex}{0.3ex}%
\def\ull#1{\def\acount{\arabic{count}} \ul{#1 \acount}}
\ull{text}
\end{document}   

If by any chance you want to increment the counter within the macro use as follows:

\documentclass{article}
\usepackage{soul}
\begin{document}
\newcounter{count}%
\setcounter{count}{0}
\setul{0.5ex}{0.3ex}%
\def\ull#1{\def\acount{\arabic{count}} \ul{#1 \acount}\stepcounter{count}}
\ull{text}
\ull{text}
\end{document}
share|improve this answer
add comment

One can also simply put extra {} around \arabic{count} :

\ul{text {\arabic{count}}}
share|improve this answer
add comment

One can use commands inside \ul as long as they expand completely to characters; so

\ul{Some text \thecount}

works. It's really not possible to use other commands, apart font switching and accent making ones; a list of preregistered commands of that kind is already included in soul, but others can be registered

\soulregister{\myfontswitch}{1}

if, for example, you have

\newcommand{\myfontswitch}[1]{\textbf{\scshape\small #1}}

(just to give a silly example). But, for example,

\newcommand{\mytext}{\mbox{xyz}}

will give Reconstruction failed without \soulregister{\mytext}{0} and no underline with it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.