Generalinput files with variable filenames

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
lobelt
Posts: 1
Joined: Thu Jul 24, 2025 10:44 am

input files with variable filenames

Post by lobelt »

I want to input a file with a variable filename.
Suppose we have the following files:

foobar.tex
foo123.tex
bar123.tex
foo456.tex
bar456.tex

The files foo123 and foo456 are latex root files and include foobar.tex.
In foobar.tex I want to include bar123 if I compile foo123. When compiling foo456 the file bar456 should be included. And so on.

I started with xstring and tried \StrBehind{\jobname}{foo}. But this gives me an empty string.

My questions are:

How to extract the needed data from \jobname

and

how to build a new filename for using with \input

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply