I'm trying to define a new command that puts text in a coloured background, reproduces it exactly how it's defined in the .tex file (in a similar way to verbatim), and won't force me to use complicated math notation in the .tex file either. The latter point is the complicated part. This is what I have so far:
\documentclass[10pt]{article}
\usepackage{color}
\definecolor{customblue}{RGB}{235,241,245}
\newcommand{\terminalCommand}[1]{\colorbox{customblue}{#1}}
\begin{document}
\begin{itemize}
\item \terminalCommand{# SUDO_EDITOR="/usr/bin/vim -p -X" visudo} %Generates missing $ errors
\item \terminalCommand{\# SUDO\_EDITOR="/usr/bin/vim -p -X" visudo} %Doesn't generate errors, but text is garbled and doesn't copy properly
\end{itemize}
\end{document}
The first \terminalCommand
generates a slew of inserted missing $
errors, which stem from the _
, among others. The second \terminalCommand
does not generate any errors, but the underscore doesn't show up in a copy and the spacing in the PDF output is a bit off, which makes it impossible to copy into a shell.
Is there a general way I could alter this command so that it reproduces the text within it in a similar fashion to verbatim? I've been using this code for larger blocks of shell commands, but I'm looking for something inline now:
\documentclass[10pt]{article}
\usepackage{color}
\usepackage{listings}
\definecolor{customblue}{RGB}{235,241,245}
\newcommand{\terminalCommand}[1]{\colorbox{customblue}{#1}}
\lstnewenvironment{terminalblock}{%
\lstset{backgroundcolor=\color{customblue},
frame=single,
framerule=0pt,
basicstyle=\ttfamily,
breaklines=true,
columns=fullflexible}}{}
\begin{document}
\begin{terminalblock}
# SUDO_EDITOR="/usr/bin/vim -p -X" visudo
\end{terminalblock}
\end{document}
I pursued a solution using \verb
, but the logical way of structuring the command (\newcommand{\terminalCommand}[1]{\colorbox{customblue}{\verb= #1 =}}
) returns errors of \verb illegal in command argument