GeneralValue of Counter to path filename

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
yiorgosb
Posts: 30
Joined: Mon Aug 02, 2010 11:56 pm

Value of Counter to path filename

Post by yiorgosb »

I have lots of images to include named consequentially, i.e. 1.eps, 2.eps, ...etc.
So, I want to "include" a counter in a filename variable to load the figures.
Something like,

Code: Select all

\newcounter{count_figs}

Some text here
\begin{figure}[h]
  \centering
      \includegraphics[width=0.5\textwidth]{images\value{count_figs}+".eps"}}
  \caption{A caption here}
\end{figure}

Obviously, the part \value{count_figs}+".eps" doesn't work.
I've tried any possible way I could think of but I have no idea if this is possible at all.
I would appreciate any suggestions.
Last edited by yiorgosb on Sun Feb 27, 2011 4:13 pm, edited 1 time in total.

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Value of Counter to path filename

Post by localghost »

Using an underscore outside math mode might cause trouble (although this is not the problem here). So it is better not to use it here. Assumed that your counter is generated with \newcounter{figcnt}, the command for inclusion should look like this.

Code: Select all

\includegraphics[width=0.5\textwidth]{images/\thefigcnt}
You can drop the suffix for the file name since the graphicx package will detect on its own which compiler engine (LaTeX, PDFLaTeX, …) is running and choose the correct driver for loading the right file.


Thorsten
yiorgosb
Posts: 30
Joined: Mon Aug 02, 2010 11:56 pm

Value of Counter to path filename

Post by yiorgosb »

localghost wrote: the command for inclusion should look like this.

Code: Select all

\includegraphics[width=0.5\textwidth]{images/\thefigcnt}
You can drop the suffix for the file name since the graphicx package will detect on its own which compiler engine (LaTeX, PDFLaTeX, …) is running and choose the correct driver for loading the right file.

Thorsten
Problem solved.
You guys are incredible.
I didn't know that to get the value of a counter you simple write thecounter.

I have to get used to that things are way toο simple in latex.
Post Reply