[Tex/LaTex] How to add text after a forward slash

symbols

I want to write this; /camera/image_raw, but it seems impossible to compile. The forward slash is not the issue, but as soon as I put text behind it doesn't work 🙁

Does anyone know a solution?

Best Answer

The underscore _ is a special character that TeX interprets as an instruction. (In this case, it's a subscript instruction for use in math mode.) To actually make an underscore symbol appear you need to use \_ (or \textunderscore). For example:

\documentclass{article}

\begin{document}

/camera/image\_raw

\end{document}

Or as Bernard mentioned, you can also use the \verb command:

\documentclass{article}

\begin{document}

\verb+/camera/image_raw+

\end{document}

However, be careful with \verb as you can't use it in the argument of a command. (See Why doesn’t verbatim work within …?.)

If your text represents a path (which it seems to) you can also use the \path command provided by the url package:

\documentclass{article}

\usepackage{url}

\begin{document}

\path{/camera/image_raw}

\end{document}
Related Question