TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to be able to change the value of a parameter inside a LaTeX document without having to change it manually. I'll explain:

There is one main program that executes another smaller one. This smaller program computes some things and creates a .txt-file with a specific name and all its results inside. Then the main program executes the LaTeX file I have to create which will process the created .txt-file into a nice pdf (using commands such as \openin\txtfile=\filename.txt and the package datatool).
Problem is that LaTeX needs to know the name of the newly created .txt-file. The main program knows the name it and will call the LaTeX file by using the cmd command > latex texfile.tex. But this won't change the value of \filename in any way.

Is there actually any possible way to change a value (of \filename) inside the LaTeX file using the cmd? Because I have absolutely no clue and Google doesn't help me either...

share|improve this question
You do pdflatex \def\filename{abc}\input{texfile} – Ulrike Fischer Jul 16 '12 at 13:52
Thanks will try it :) – Didii Jul 16 '12 at 15:17
up vote 2 down vote accepted

Thanks to Ulrike Fischer for the solution:

> pdflatex \cmd\input{texfile}

\cmd can be any command LaTeX recognizes. And input{texfile} pastes all contents of texfile.tex into the cmd.

share|improve this answer

Potentially you might want to change the jobname

latex -jobname=$filename texfile.tex

where $filename is the name of your .txt file. Then inside your .tex file you could use


This approach would change the name of the final output and all auxiliary files from texfile.* to $filename.*, which may or may not be desirable.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.