I would like to make the character `
active in one environment so that `some text`
will be formatted using black background and white for the text.
This feature must be activated only inside the environment.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityYou need to make `
active and read everything up to the next `
. The colors can be set using \colorbox
and \textcolor
from the xcolor
package.
You might also want to compensate for the added left/right space as shown below.
\documentclass{article}
\usepackage{xcolor}
\catcode96=\active
\newenvironment{myenv}{%
\catcode96=\active% ASCII ` = 96
\def`##1`{%
\hspace{-\fboxsep}%
\colorbox{black}{\textcolor{white}{##1}}%
\hspace{-\fboxsep}%
}%
}{%
}
\catcode96=12
\begin{document}
`text`
\begin{myenv}
text text text
text `text` text
\end{myenv}
`text`
\end{document}
With the \hspace
s you get:
Without you get:
You could also just take half the \fboxsep
away to get an intermediate result.