Andrew
Andrew

Reputation: 91

How can I include a large block of regex with LaTeX?

Is it possible to include a large block of a regex (like this one: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html) without escaping all colliding characters first?

I think of something like

\begin{following_section_will_not_be_parsed_by_latex}
(a+?b)
\end{...}

Upvotes: 4

Views: 2726

Answers (3)

Andrew
Andrew

Reputation: 91

You can include \usepackage{listings} and then use

\begin{lstlisting} [code|regex|whatever] \end{lstlisting}

Upvotes: 5

Alok Singhal
Alok Singhal

Reputation: 96131

Look at fancyvrb package. From the README:

The `fancyvrb' package provides very sophisticated facilities for reading and writing verbatim TeX code. Users can perform common tasks like changing font family and size, numbering lines, framing code examples, colouring text and conditionally processing text.

So you can do something like:

\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim}[fontsize=\small,frame=single,label=RFC822 regexp]
...
\end{Verbatim}

In order to not clutter your Latex file with the huge regex, you can include a file verbatim as well.

Upvotes: 4

Aaron Digulla
Aaron Digulla

Reputation: 328594

Use a verbatim block. But it won't look very nice :(

Upvotes: 2

Related Questions