GeneralModify file names in a command definition

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
normanj
Posts: 3
Joined: Sun Jul 22, 2012 2:47 am

Modify file names in a command definition

Post by normanj »

I'm preparing a large document with approximately 300 included source files. Depending on certain flag settings, I also add other files such as images. I would like to do this as a command definition so I don't duplicate the inclusion logic (which can change) in the master document 300 times, The name of the included .tex file being passed in as a parameter.

When included, the image file has the same file stem as a the included .tex file (e.g. exclusions.tex and exclusions.jpg).

Rather than pass in both file names, It would be more elegant and less error prone if I could pass a single argument to the new command and generate the file names from that, for example, if I pass in donorItems as a file stem and generate donorItems.tex and donorItems.jpg to use within the command. However, I have not been able to see how this can be done.

Is someone able to suggest a way this might be accomplished, or suggest an alternative way to achieve the same result?

Thank you.

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Modify file names in a command definition

Post by Johannes_B »

I think what you are looking for is \jobname
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Modify file names in a command definition

Post by cgnieder »

normanj wrote:for example, if I pass in donorItems as a file stem and generate donorItems.tex and donorItems.jpg to use within the command.
I believe what you want might be easily possible. However, I didn't really understand your aim. What Do you mean by “generate”? The files themselves should be generated through TeX? Or are they present already but you want to include them? The latter would be as easy as

Code: Select all

\newcommand*\myinclude[1]{%
  \input{#1.tex}\par
  \inlcudegraphics{#1.jpg}%
}

\myinclude{donoritems}
Can't you post some minimal code showing what you're doing right now and some code what you would like your source to look like ideally?
site moderator & package author
normanj
Posts: 3
Joined: Sun Jul 22, 2012 2:47 am

Modify file names in a command definition

Post by normanj »

Thanks cgneider. Your suggestion does what I need, and is simpler than I had envisaged. To answer your question, what I intended (and said) was to generate the file names, not the files themselves, which is what you provided.

Thanks again
Post Reply