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

So here is the situation : I wanted latex to read some commands when I include another file, and for that I defined a new \include command like this :



It works beyond all hopes! But now I'd like to still be able to use RefTeX's toc browser with my new \includeas command.

And here is the problem : (from RefTeX's manual)

User Option: reftex-include-file-commands

List of LaTeX commands which input another file. The file name is expected after the command, either in braces or separated by whitespace.

As you can see, having an optional argument in square brackets after the macro is a problem for RefTeX.

Is there any way I can bypass it?

At the moment I have a quick fix by turning the optional #1 argument to mandatory #2, but it relies on the fact I actually provide the argument all the time, which won't always be the case.


File main.tex



 % The test is to press C-C = , not to try to compile!


%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

File foo.tex :

share|improve this question
up vote 4 down vote accepted

You can make the argument optional on the flip side of the command:


Then you will call it as:

Without optional
With optional

However you should not start a regular sentence with [ after a use of the command \includeas.

share|improve this answer
Awesome, thank you very much. You last warning is right, but it won't happen, there is about nothing in my main file. One thing only, for the command to have the intended input, I had to replace the second definition by \def\includeas@#1{ \foo{Default} \include{#1} } No big deal though. Thanks again! – T. Verron Dec 1 '11 at 14:43
Ahh. If you need a default value i would do like this instead: \makeatletter \def\includeas#1{ \@ifnextchar[{\includeas@opt{#1}{\includeas@opt{#1}[Default]} } \def\includeas@opt#1[#2]{ \foo{#2} \include{#1} } \makeatother – zeroth Dec 1 '11 at 14:49
Ok thanks, I can see the advantages of this version. :) – T. Verron Dec 1 '11 at 16:47

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.