3

im trying to color part of an expression with a percent symbol and its not working, the area comes out blank after running latex, other stuff works, but anything containing a percent sign ends up messed up if i try to color it

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{color}
\title{\LaTeX}
\date{}
\begin{document}

This works:\\
{\color{red} (\mathrm{\\045 21})} \\
 this does not:
{\color{red} (\mathrm{\%o21})}


\end{document}

how do i do that?

David Carlisle
  • 757,742
mike-m
  • 235

1 Answers1

6

Remarks

You need to wrap all math related code in a math mode environment, i.e. either enclosing them in $...$ or \[...\].

Implementation (Bad!)

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{color}
\begin{document}
This works:\\
{\color{red} ($\mathrm{\\045 21}$)} \\
 this does not:
{\color{red} ($\mathrm{\%o21}$)}
\end{document}

Output

s

Much better

Using math mode and \mathrm only, where you need it.

\documentclass{standalone}
\usepackage{color}
\begin{document}
This works: {\color{red} $(045 21)$}
This works, too: {\color{red} $(\%\mathrm{o}21)$}
\end{document}

Output

s2

David Carlisle
  • 757,742
Henri Menke
  • 109,596