1

I need to highlight some text with the command \emph whose content is "valeurAop += analogRead(mesure_aop)" : the compilation gives me an error, I think it is due to the mathematical symbols.

I tried \emph{opvalue} $+= $ \emph{analogRead (aop_measure) but I still get the same error:"Missing $ inserted$

How can I solve this problem?

Thanks

Nicolas
  • 1,023
  • 1
    Never use underscore in text alone. If you want underscore, use a backlash preceding it, like this \_. That's because underscore is designed to be used in math mode to display subscript. – SolidMark Jun 26 '21 at 15:50

2 Answers2

1

Like this?

enter image description here

\documentclass{article}

\begin{document} $\mathit{opvalue} += \mathit{analogRead(aop_measure)}$

$\mathit{opvalue}\mathrel{+=}\mathit{analogRead(aop_measure)}$ \end{document}

The second example is suggested by @David Carlisle).

Zarko
  • 296,517
1

You want to use a math formula. In order to do this, you should

  1. define a higher level commands for the variables;
  2. define a math symbol for plus-equal, which should have the two parts next to each other;
  3. use properly the underscore.
\documentclass{article}
\usepackage{amsmath} % not necessary for the example, but recommended

\newcommand{\lvar}[1]{\mathit{#1}} \newcommand{\pluseq}{\mathrel+=}

\begin{document}

$\lvar{opvalue} \pluseq \lvar{analogRead(aop_measure)}$

\end{document}

If you later change your mind, you can decide that the argument to \lvar is typeset upright, boldface or whatever by just changing the definition.

With \mathrel+= we make the whole combination a relation symbol, which seems the appropriate choice. TeX will never add space between consecutive relation symbol, nor break a line in the middle.

enter image description here

egreg
  • 1,121,712