Text Formattingfilename as text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
lowilly
Posts: 3
Joined: Mon Sep 07, 2015 2:12 pm

filename as text

Post by lowilly »

Hello everyone!
I'm new to the world of Latex and I need some help...
I need to write in my article a filename such as "pippo.txt"
but if I try to compile it Latex gives me this error "missing $ inserted"
I think he tries to find the file pippo.txt...how to avoid this and make latex just print the filename?

Recommended reading 2024:

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

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

filename as text

Post by Stefan Kottwitz »

Hi lowilly,

welcome to the forum!

This should not be a problem. Test this file, it works:

Code: Select all

\documentclass{article}
\begin{document}
pippo.txt
\end{document}
You can click "Open in WriteLaTeX" above to directly open it in the online editor.

So, I guess, your actual file name is not pippo.txt but contains special characters like an underscore, such as pippo_1.txt. In that case, you would get this error, because the underscore _ is for subscripts in math mode.

If you would load the url package or hyperref, the path command is handy and fixes it:

Code: Select all

\documentclass{article}
\usepackage{url}
\begin{document}
This is the file: \path{pippo_1.txt}
\end{document}
It also prints the path or file name in typewriter font, which is pretty popular, but this can be changed.

Stefan
LaTeX.org admin
lowilly
Posts: 3
Joined: Mon Sep 07, 2015 2:12 pm

Re: filename as text

Post by lowilly »

Hi Stefan, thank you for the quick answer!
You got it! The filenames contains the underscore character!
The problem is that i don't have those file, so I don't need to insert the path, I just need to print the files name "arm256_start.elf, arm384_start.elf, arm496_start.elf"
I solved it putting an "\" before the "_" but i don't know if it's the right way to solve the problem

Now my problem is to correct this "( gpu_mem = xx) "
User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

filename as text

Post by Stefan Kottwitz »

\path can also be used for simple filenames. But \_ should work. It should also work in gnu_mem. Btw. while the whole expression should be in math mode, gnu_mem should be text, such as here:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\text{gpu\_mem} = x$
\end{document}
Stefan
LaTeX.org admin
lowilly
Posts: 3
Joined: Mon Sep 07, 2015 2:12 pm

Re: filename as text

Post by lowilly »

ok!
Solved!
Thank you so much!
Post Reply