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
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
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: 9201
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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
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