# combining soul package and color one in a newcommand

I have to use \st (from soul package) for crossing a line over a word in a text file. In addition, for presenting a specific replaced word instead of the first one, I use {\color{blue} second word}.

For example: \st{handling} {\color{blue}studding} of very large.

In order to be similar as below image:

How can I compress two commands (\st and afterward \color) in only one command to gain similar output? (For example, \command{first-word, second word} of very large

• \newcommand{\command}[2]{\st{#1}\ \textcolor{blue}{#2}} and the usage is \command{handling}{studding} – MadyYuvi Oct 10 '19 at 9:07

You can just define a new command using \newcommand\macroname[<arg count>]{<replacement>} (arguments are used by #<num>, up to 9 arguments are supported), to get an a bit more powerful interface you can load the xparse package and use \NewDocumentCommand. The following defines a macro that takes a mandatory argument, followed by an optional one specifying the colour and another mandatory argument. The first will be stroked out and the latter will be coloured:

\documentclass[]{article}

\usepackage{soul}
\usepackage{xcolor}
\usepackage{xparse}

\NewDocumentCommand \replacing { m O{blue} m }
{%
\st{#1}
\textcolor{#2}{#3}%
}

\begin{document}
an appropriate \replacing{handling}{studding} of very large.
\end{document}


A different colour can be used with \replacing{handling}[red]{studding}.

EDIT: A variant that has a coloured line for the strike. It has another optional argument, you can specify the line colour with \replacing[green]{handling}[red]{studding}.

\documentclass[]{article}

\usepackage{soul}
\usepackage{xcolor}
\usepackage{xparse}

\NewDocumentCommand \replacing { O{red} m O{blue} m }
{%
\begingroup
\setstcolor{#1}%
\st{#2}%
\endgroup
\space
\textcolor{#3}{#4}%
}

\begin{document}
an appropriate \replacing{handling}{studding} of very large.
\end{document}

• Thank you so much for your instruction. Can you tell me how I change the color of line for instance red instead of black? – Irreversible Oct 10 '19 at 9:51