Tag Info

Hot answers tagged

16

\documentclass{article} \usepackage[T1]{fontenc} \setlength\textwidth{20em} \begingroup \makeatletter \gdef\plaintext{\let\do\@makeother\dospecials\catcode32=10\relax\xplaintext} \catcode`\!=0 !catcode`\\=12 !catcode`{=12 !catcode`}=12 !catcode`(=1 !catcode`)=2 !long!gdef!xplaintext#1\end{plaintext}(% #1!end(plaintext)) !endgroup \begin{document} ...


11

listings provides the possibility to escape to LaTeX inside a listing, see section 5.12 Escaping to LaTeX of the manual for details. The basic idea is to set an escapechar which switches to LateX and back: \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting}[basicstyle=\ttfamily,columns=fullflexible,gobble=2,escapechar=ß] ...


8

You have to do \usepackage{verbatim} \newenvironment{listing} {\minipage{\linewidth}\verbatim} {\endverbatim\endminipage} There's almost the same example on page 3 of the package documentation, see the definition of the fred environment. Note that \begin{minipage} executes (among other things) \minipage and similarly \end{minipage} executes ...


6

You can do this with \newminted command \documentclass{article} \usepackage{minted} \newminted[lstlisting]{scala}{} \begin{document} \begin{lstlisting} #include <stdio.h> #define N 10 /* Block * comment */ int main() { int i; // Line comment. puts("Hello world!"); for (i = 0; i < N; i++) { puts("LaTeX is also ...


6

This approach uses \detokenize, but wraps it in a paragraph parser, which will format lines and indeed paragraphs in a verbatim-like manner. EDITED to incorporate a trap for the % character, taking a nod from David's approach. However, there is (at least) one area where it will break: unmatched braces {}. However, this limitation may or may not pose an ...


5

There are several cases where \verb can be dispensed with. Suppose you're writing the manual for a package and you want to typeset command or environment names; then a couple of definitions such as \newcommand\cs[1]{\texttt{\string#1}} \newcommand\env[1]{\texttt{\string\begin\string{#1\string}}} will do. Example: \documentclass{article} ...


4

I would do this: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \newcommand\textinput[1]{{% \catcode`\$=12 \catcode`\&=12 \catcode`\_=12 \catcode`\^=12 \catcode`\#=12 \catcode`\%=12 \catcode`\~=12 \input{#1}}} \begin{document} \section{zzz} \textinput{zzz.txt} \end{document} with input file aaa & bbb is 5% of ...


4

Here is a version without the use of packages (i.e., works in plain verbatim environment). I make ? (or any char of your choosing) active and employ ! (or any char of your choosing) as a delimiter. With this syntax, ?!My footnote! is the equivalent of \footnote{My footnote}. \documentclass{article} \textheight=1.5in\relax% FOR THIS MWE ONLY ...


4

To get verbatim content inside the align* environments, my verbatimbox package can help. \documentclass{article} \usepackage{amsmath,verbatimbox} \begin{document} \begin{myverbbox}{\lineA}\int \sin x\,dx\end{myverbbox} \begin{myverbbox}{\lineB}\int{\sin x}\,dx\end{myverbbox} \begin{align*} \int \sin x\,dx && \lineA\\ \int{\sin x}\,dx && ...


4

I am not entirely sure that I understood what you want. However, your MWE can easily be achieved with xparse and its v type argument: \documentclass{article} \usepackage{qrcode,xparse} \NewDocumentCommand{\script}{v}{% \texttt{#1} \qrcode{#1}% } \begin{document} \script{test} \script{&$\#$} \end{document} Keep in mind, though, that now since now ...


3

beamer has the columns environment, makes sense to use that I think. Note that you need the [fragile] option to the frame in order to use verbatim and the like. \documentclass{beamer} \begin{document} \begin{frame}[fragile] \begin{columns}[t] \column{0.5\textwidth} \begin{verbatim} SELECTION test1 JET_N 25000 >= 1 JET_N 25000 >= 2 JET_N 25000 >= ...


2

Use \begin{frame}[fragile]. This option is needed when the content contains verbatim.


2

One possible work around is to use a temporary file. First you need a macro to write to the file (\jobname.tmp was used here) and read it twice using the regular and the listing input commands: \usepackage{listings} \newwrite\tempfile \newcommand{\example}[1]{ \immediate\openout\tempfile=\jobname.tmp \immediate\write\tempfile{#1} ...


2

I extended the answer from alexis to cover more formats: normal format (diff), unified format (diff -u), context format (diff -c) and diffs from Git (git diff): \lstdefinelanguage{diff}{ sensitive=true, % diff command line morecomment=[f][\color{gray}][0]{diff}, % commit identifiers for git diff morecomment=[f][\color{gray}][0]{index}, % hunk ...


2

You can use the verbatim package to define a new environment that defines a character to enclose the footnote text. \documentclass{article} \usepackage{verbatim} \textheight=3cm % just not to waste space \newcommand{\vfchar}[1]{% % the usual trick for using a "variable" active character \begingroup\lccode`~=`#1 \lowercase{\endgroup\def~##1~}{% % ...


2

You can't use \verb inside align*, just like in the argument to any other command; align is a special environment that reads its contents before starting typesetting and this has the consequence that \verb is not allowed. If you want to make examples of input and output, you can use array: \documentclass{article} \usepackage{array,booktabs} ...



Only top voted, non community-wiki answers of a minimum length are eligible