On any SE post one can use the backtick symbol ("`") in order to mark some text as being a piece of code, or computer output. For example: void main().
Is there a way to make use of "`" the same way in a LaTeX document?
On any SE post one can use the backtick symbol ("`") in order to mark some text as being a piece of code, or computer output. For example: void main().
Is there a way to make use of "`" the same way in a LaTeX document?
In addition to Werner's answer, the same is possible with the listings package. To undefine the shorthand use \lstDeleteShortInline`.
Be aware, that using ` as an escape character for inline code will most likely clash with language feature packages such as babel.
\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}
\lstMakeShortInline`
Here is some inline code `\int f(x) \, \mathrm{d}x`
\end{document}
*Sometext comes out as $\ast$Sometext.
– alelom
Sep 09 '22 at 11:01
You can define your own verbatim shorthand using fancyvrb's \DefineShortVerb:
\documentclass{article}
\usepackage{fancyvrb}
\DefineShortVerb{\`}
\begin{document}
On any SE post one can use the quote in order to highlight a text.
For example, `this text is highlighted`.
\end{document}
To remove this functionality, use \UndefineShortVerb{\`}, as it may interfere with other uses of ` within your code.
\DefineShortVerb{\}when also using\usepackage{graphicx}:! Missing number, treated as zero.
It is more natural to use " or | rather than ` for this purpose, since ``foo'' is translated to “foo” in LaTeX.
There are several packages to define a short verbatim command for this. The basic one is shortvrb, which is part of LaTeX base package doc:
\documentclass{article}
\usepackage{shortvrb}
\MakeShortVerb|
% \DeleteShortVerb|
\begin{document}
Short verbatim: |foo#bar|
\end{document}
As Werner and Henri Menke said, you can also use fancyvrb, gmverb, newverbs for this functionality, or use listings with syntax highlight support.
Sometimes, however, you don't want to use verbatim text, only special fonts or color is needed. Then you can use some tricks to define a one-character command yourself:
\documentclass{article}
\newcommand\MakeShortHighlight[2][\texttt]{%
\begingroup\lccode`\~=`#2\lowercase{\endgroup
\def~##1~{#1{##1}}}%
\catcode`#2=\active}
\newcommand\DeleteShortHightlight[1]{%
\catcode`#1=12 }
\usepackage{xcolor}
\begin{document}
\MakeShortHighlight\"
Short highlighted: "typewriter text"
\MakeShortHighlight[\textcolor{red}]\|
Short highlighted: |red color|
\end{document}
Yes, you can use the back-ticks and the indentation of four spaces as in markdown, using well ... the markdown package:
\documentclass[a5paper,12pt]{article}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0em}
\usepackage{markdown}
\begin{document}
\begin{markdown}
A minimal working example
\documentclass{article}
\def\foo#1{#1}
\begin{document}
\foo{bah}
\end{document}
The macro `\def\foo#1{#1}` does not anything
\end{markdown}
\end{document}
This doesn't perfectly answer your question, but I prefer the use of commands to perform the action you desire. Perhaps someone else will find this useful.
\documentclass{article}
\newcommand{\code}[1]{\texttt{\detokenize{#1}}}
\begin{document}
This command allows you to type \code{void main()} inline in your paragraphs.
\end{document}
Disclaimer: This command does not handle pound signs (#) properly. Please feel free to comment if you know how to extend this command to handle pound signs (bonus points if it's without any dependencies!).
\code{100%} or \code{ single { brace }
– Henri Menke
Jun 22 '17 at 06:51
*emphasis*and the like. – David Z Mar 30 '17 at 03:27pretags) for “highlighting” or any other kind of visual effect. Its primary purpose is not visual, but semantic, it tells the computer that the text is supposed to be code. Most visual browsers render that as a monospace font with gray background, but alternative browsers, like screen readers for the blind, have to do something to allow text to be understood as code. This can make the text very difficult to understand as prose—reading letter-by-letter is not unheard of. Please be considerate of accessibility. – KRyan Mar 30 '17 at 12:59*,**, and***: http://tex.stackexchange.com/questions/236439/use-markdown-style-formatting-for-bold-and-italic – Steven B. Segletes Mar 31 '17 at 10:12