Text Formattingtexttt{} inside an environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
adkdk
Posts: 9
Joined: Sun Apr 18, 2010 11:39 am

texttt{} inside an environment

Post by adkdk »

Hi everyone.

I'd like to create my own environment for custom source code formatting (monotype, verbatim, small font etc). The problem is: how to format text as monospace? When declaring an environment, I must tell LaTeX what to put before and after environment contents. So I wrote:

Code: Select all

\newenvironment{code} {\texttt{ } { }}
to open \texttt{ tag before contents and close it after contents.
Piece of code is formatted using:

Code: Select all

\begin{code}
blah blah blah
\end{code}
However, it's not working - only first character is formatted, interpreter seems to be ignoring the brackets.

Any ideas how to put texttt{} inside environment?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: texttt{} inside an environment

Post by josephwright »

As you want verbatim, have you considered using the alltt package or perhaps listings?
Joseph Wright
adkdk
Posts: 9
Joined: Sun Apr 18, 2010 11:39 am

Re: texttt{} inside an environment

Post by adkdk »

Yes, I can simply use listings. However, I'm just curious, how to deal with texttt, textbf and other similar tags in environments.
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

texttt{} inside an environment

Post by josephwright »

Don't use the macros, use the appropriate series/family declarations, such as \bfseries, \ttfamily, etc.
Joseph Wright
Post Reply