I'm frequently creating presentations with beamer and need both the handout and the presentation itself. To avoid editing the file when I need to compile the other, I use \ifdefined\ishandout ... at the beginning of the presentation and have a separate file for the handout that contains nothing but


Since the handout file is always named following the schema topic_handout.tex I'm looking for a way to strip the inner _handout so I can use the same handout file for all presentations without changing the content. I found \jobname which gives me topic_handout, so I just need to strip the constant string _handout and add .tex to the argument in \input. Since this happens before the document class is declared, I cannot use any packages. Any help is welcome.

  • Welcome to TeX.sx! Please use backticks ` to mark inline code, file names etc. Jun 28, 2011 at 13:49
  • You actually can use packages before \documentclass by using \RequirePackage instead of \usepackage. But you should be careful anyway. Also you can use \PassOptionsToClass{handout}{beamer} and \mode<handout>{...} instead of \def\ishandout{1} and \ifdefined\ishandout ..., respectively. Note that \jobname returns the file name as characters (catcode 12, "other") and not as letters (catcode 11), which must be taken into account for string comparison and manipulation. Jun 28, 2011 at 13:49
  • Thanks for the hint, will use the backticks in the future. Jun 28, 2011 at 15:39

2 Answers 2


It's not very clear what the problem is; as I have understood it, you want that

pdflatex topic_handout

actually inputs topic.tex after defining \ishandout. This can be done all on the command line, without an auxiliary file topic_handout.tex:

pdflatex "\def\ishandout{1}\input{topic}"

If you don't want to use the command line, your topic_handout.tex file may be


  • +1, using \detokenize instead of \@onelevel@sanitize is a good idea. Jun 28, 2011 at 15:57

You can define a macro with _handout in the parameter text, so that this part is then removed. This requires a little more advanced coding. Here my try to explain it:

You need to use the plainTeX macro \def instead of LaTeX's \newcommand for this. One issue is that all characters except spaces in \jobname are returned with catcode 12 other and are not letters (catcode 11) as normal. To define a macro with the correct catcodes you can use e.g. LaTeX's \@onelevel@sanitize macro to turn the whole macro definition to catcode other. Then you need a lot of \expandafters to expand the helper macro before the removal macro is defined.

% somename_handout.tex
\@onelevel@sanitize\handoutstr% to get right catcodes!

% better:


In addition it is better to use \PassOptionsToClass{handout}{beamer} instead of \def\ishandout{1}. This passes the handout option directly to the beamer class. Then in the presentation file you can use \mode<handout>{ handout-only code }:

% somename.tex

  % handout-only code
 % ...

% ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .