I'm writing a document with a ton of pseudocode and it's very tedious to keep wrapping code objects in {\tt text}. It would be so much nicer to, well, do what StackExchange does! There's a one-character symbol, the back-tick, just like for math there's the dollar-sign. Is there any way to accomplish the same thing in LaTeX?
Asked
Active
Viewed 675 times
5
Phelype Oleinik
- 70,814
Addem
- 867
3 Answers
15
\documentclass{article}
\usepackage{shortvrb}
\MakeShortVerb|
\begin{document}
this |and| that or |the other|
\end{document}
shortvrb is in the core base latex distribution.
David Carlisle
- 757,742
-
I suspect this is conflicting with the vertical bars that I'm using to declare borders in tabular environments. Is that right, and if so, do you happen to know a fix? – Addem Jun 08 '19 at 18:01
-
1@Addem you can turn it off before the table (
\DeleteShortVerb|) or use any other character that you do not use, such as\MakeShortVerb!or any other character – David Carlisle Jun 08 '19 at 18:04
11
Use fancyvrb and \DefineShortVerb (although you might not want to use `)
\documentclass{article}
\usepackage{fancyvrb}
\DefineShortVerb\`
\begin{document}
I'm writing a document with a ton of pseudocode and it's very tedious to keep wrapping code objects in
`{\tt text}`. It would be so much nicer to, well, do what StackExchange does! There's a one-character
symbol, the back-tick, just like for math there's the dollar-sign. Is there any way to accomplish the same
thing in LaTeX?
\end{document}
Phelype Oleinik
- 70,814
-
This might cause problems when you want to use quotation marks. A chacter like
|or@might be more suitable – AJF Jun 07 '19 at 19:46 -
@AJFarmar That's exactly why I said "you might not want to use
`", I just used it to imitate the markdown syntax (I could've used more emphasis on that warning, though :-). – Phelype Oleinik Jun 07 '19 at 19:56
4
What StackExchange does is markdown, so you can also use the markdown package:
\documentclass{article}
\usepackage{markdown}
\begin{document}
\begin{markdown}
This `and` that or `the other`
\end{markdown}
\end{document}
Or more simple, write a markdown file and export it to LaTeX:
This `and` that or `the other`
The bonus point of this approach is avoid also many other tedious commands, not only those for verbatim text.
-
I hope you don't mind me adding a link to the package - it was new to me and presumably to others, and looks useful – Chris H Jun 07 '19 at 07:54


ctrl+l,ctrl+t. – Tvde1 Jun 07 '19 at 10:34\tt,\bf, etc.) in LaTeX. Use the proper more-letter variants (\ttfamily,\bfseries, etc.) – Phelype Oleinik Jun 07 '19 at 19:58