3

I am currently working on revising a manuscript, and I was wondering how to define a LaTeX command that allows for simultaneous text coloring in dark-red and highlighting. The purpose is to efficiently mark revisions in the manuscript.

the below command is not work correctly.

\newcommand{\rev}[1]{{\color{red!70!black} \hl {#1} }}

Best regards,

1
  • 1
    Greetings! While it's entirely ok to upvote good answers right away, the site guidelines strongly recommend waiting several hours, and maybe even a day or two, before "accepting" any given answer. That way, you don't discourage other would-be answer providers from posting alternative, possibly even more suitable, answers.
    – Mico
    Commented Nov 30, 2023 at 15:03

2 Answers 2

4

The xcolor package provides a macro called \colorbox, which can be combined with \textcolor to generate the desired effect.

In the following example, the utility macro \highlight takes three arguments -- the background color, the foreground color, and the word(s) to be highlighted, while the macro \rev hard-codes the background and foreground colors (as yellow and red, respectively).

enter image description here

If you load xcolor with the option svgnames, you'll have access to a named color called Crimson, which is slightly darker than red.

\documentclass{article}
\usepackage{xcolor} % for '\textcolor' and '\colorbox' macros
% Define two utility macros:
\newcommand\highlight[3]{\colorbox{#1}{\textcolor{#2}{#3}}}
\newcommand\rev[1]{\highlight{yellow}{red}{#1}} % hard-coded color choices

\begin{document}

I wish to \colorbox{yellow}{\textcolor{red}{highlight}} a word.

\smallskip
I wish to \highlight{yellow}{red}{highlight} a word.

\smallskip
I wish to \rev{highlight} a word.

\smallskip
I wish to \highlight{yellow}{blue}{\textbf{highlight}} a word.

\end{document}
2

Try this:

\documentclass{article}
\usepackage{xcolor} % For text color
\usepackage{soul}   % For highlighting

% Define the command for coloring and highlighting
% This will color the text in dark red
\newcommand{\rev}[1]{\textcolor{red!70!black}{\hl{#1}}}

\begin{document}

% Sample usage of the \rev command
Here is some regular text and here is \rev{revised text} to demonstrate the command.

\end{document}

enter image description here

To change the highlight color:

\documentclass{article}
\usepackage{xcolor} % For text color
\usepackage{soul}   % For highlighting

% Define a custom highlight color
\sethlcolor{lightgray} % You can change 'lightgray' to any color you prefer

% Define the command for coloring and highlighting
% This will color the text in dark red
\newcommand{\rev}[1]{\textcolor{red!70!black}{\hl{#1}}}

\begin{document}

% Sample usage of the \rev command
Here is some regular text and here is \rev{revised text} to demonstrate the command.

\end{document}

enter image description here

4
  • Thank you so much for your assistance. The provided solution works perfectly for regular text in the manuscript. However, when attempting to apply it to specific lines in the pseudocode, which involves multiple if-then-else statements with multiple curly braces, I encountered several errors such as "Paragraph ended before," "Extra }," etc. Despite careful revisions, the highlighting doesn't seem to work within the pseudocode. Any insights or suggestions on how to address this issue would be greatly appreciated. Commented Nov 30, 2023 at 15:05
  • @husinalhajahmade - Please provide an example of pseudocode you may wish to highlight.
    – Mico
    Commented Nov 30, 2023 at 15:07
  • You may need to use \{ and \}, to escape the curly braces
    – John Smith
    Commented Nov 30, 2023 at 15:45
  • Or you might need to define a different custom command specifically for use within the pseudocode environment
    – John Smith
    Commented Nov 30, 2023 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .