GeneralInput file inside a caption

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Input file inside a caption

Post by cbustaam »

Hi all,
I'm trying to input a txt file in the caption of a floath environment:

Code: Select all

\caption{Results of: \input{name.txt}}
However it doesn't work. Also, I try to do the following:

Code: Select all

\newcommand{\myname}{\input{name.txt}}
\caption{Results of: \myname}}
But it didn't work to. How can I make this?
Bests
Last edited by cbustaam on Thu Mar 31, 2011 10:27 pm, edited 1 time in total.
"Show me your .emacs and I'll tell you who you are." -- modified proverb

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

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Input file inside a caption

Post by 5gon12eder »

Solution 1:

If you don't need the contents of your external file inside the list of figures but just in the caption, then you may use

Code: Select all

\caption[]{\input{name.txt}}
The optional argument is what will go to the list of figures alternatively.

Solution 2:

Declare a robust command:

Code: Select all

\DeclareRobustCommand{\myname}{\input{name.txt}}
that will work as you wanted it.
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Input file inside a caption

Post by localghost »

It may help if you protect the \input command in the (moving) argument of \caption.

Code: Select all

\caption{Results of: \protect\input{name.txt}}

Thorsten
User avatar
cbustaam
Posts: 57
Joined: Mon Sep 01, 2008 10:17 pm

Re: Input file inside a caption

Post by cbustaam »

The both solutions work well. Thank you.
Bests
"Show me your .emacs and I'll tell you who you are." -- modified proverb
Post Reply