Text FormattingWriting long file names with many underlines

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
MechWright
Posts: 2
Joined: Fri Nov 06, 2020 1:43 pm

Writing long file names with many underlines

Post by MechWright »

Hi,

I have to write many file names with many underlines; this can be done in many ways, but all seem quite clumsy.

1. The obvious way is to replace every _ with \_
2. The another one is to use \begin{verbatim} and \end{verbatim}
3. I also tried
\newcommand{\bv}{\begin{vertabim}}
\newcommand{\ev}{\end{verbatim}}

Now, however, \ev gives an error.

Is there a neat solution?

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

Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Writing long file names with many underlines

Post by Ijon Tichy »

The verbatim environment is somehow special, so you cannot use \begin{verbatim} or \end{verbatim} inside the definition of other environments or marcos like you've tried. See the manual of package verbatim for more information about defining you own verbatim environment.

However, you can use \verb|filename___with_many___underscores|. But this usually cannot be done inside the argument of another command. See an introduction to LaTeX for more information about (very special command) \verb.

Or you can use package url to use, e.g., \url{filename___with_many___underscores}. Again there are restrictions (and solutions for them). See the manual.

There are many more packages like listings, moreverb, fancyvrb, underscore

BTW: Shortcut commands like \bv, \ev are usually not recommended, because they can break syntax highlight of several editors and make the code harder to read. You should instead of such two-character-macros use an editor that supports command auto completion.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
MechWright
Posts: 2
Joined: Fri Nov 06, 2020 1:43 pm

Writing long file names with many underlines

Post by MechWright »

\verb|filename___with_many___underscores| works perfectly for my purposes. Thanks!

Out of curiousity, what is this | instead of { ?
I have never seen LaTeX commands used in this way.
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Writing long file names with many underlines

Post by Ijon Tichy »

You can also use another character as delimiter. As I said: \verb is special and please read an introduction to LaTeX. It should explain it.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply