# reftex: include from tex/

In order to keep doc dir clean, I keep a master file in the top level of the doc, and other files in folders:

.
├── bib
│   └── refs.bib
├── img
│   ├── img1.png
│   └── img2.png
├── tex
│   ├── part1.tex
│   ├── part2.tex
│   └── part3.tex
├── tmp
└── master.tex


I import tex files from tex with:

% include from tex/
\usepackage{import}
\def\includeFromTex#1 {\subimport{tex/}{#1.tex}\include{#1}}


Example usage:

\begingroup\let\clearpage\relax % tweak that stops include from starting with newpage
\includeFromTex{10_-_calc}
\includeFromTex{20_-_disc}
\includeFromTex{30_-_app}
\endgroup


And every file under tex/ starts with:

% -*- TeX-master: "../master.tex" -*-


This works fine with tex, but breaks reftex ability to build toc, and reference things. Is it possible to notify reftex that I keep tex files under tex/?

Edit:

Since I can't tweak reftex to do that, I moved texs to the doc dir:

.
├── bib
│   └── refs.bib
├── img
│   ├── img1.png
│   └── img2.png
├── tmp
├── 10_-_part1.tex
├── 20_-_part2.tex
├── 30_-_part3.tex
└── master.tex


Now I'm using plain \input{} for files and everything works (latex and reftex).

(BTW if one numbers the parts, the the master file will always be the last one. In this case it is possible to make it TeX-master automatically:

% -*- eval: (setq TeX-master (car (last (directory-files default-directory nil ".*\\.tex\$")))) -*-


one should put this line at the top of child tex files)

• why use a delimited argument? also why not simply \include{tex/part1} ? Mar 3, 2015 at 10:59
• @DavidCarlisle: include starts each file with a new page. Normally I don't need that. That's why I'm using import instead of include. Mar 3, 2015 at 11:01
• @Adobe, the reftex parser only looks at \include and \input, so it might simply be easier to store the normal value of \include in a macro via \let\oldinclude\include, and then redefine \include. I've used that trick before to get around exactly this issue where I wanted a specialized input command, but also wanted reftex and auctex to be able to find and parse stuff. Mar 3, 2015 at 12:20
• @Adobe you can use \def if you must but \def\foo#1 {....} defines the argument of \foo not to be the next {} group but to be everything up to the next space. \def\foo#1{....} would be the thing to use to define a command as \newcommand would define it with an argument delimited by {} Mar 3, 2015 at 13:43

If you do not need the \includeonly system and do not want your included files to start on a new page just use

\input{tex/10_-_calc}
\input{tex/20_-_disc}
\input{tex/30_-_app}


\def\includeFromTex#1 {..


defines \includeFromTex to take as argument everything up to the next space (or end of line) so in your example use the {} were being ignored and the end of line white space was required.

The redefinition of \clearpage to \relax would certainly break the \include mechanism and can result in data being lost or written to the wrong aux file.

reftex working showing the section picked up in the input file:

• But using input one can't store tex files under tex/. Actually the problem is not with latex: I succedded in making latex aware that files are under tex/, but with emacs's reftex. Mar 3, 2015 at 18:20
• @Adobe of course you can, why ever not? Mar 3, 2015 at 18:40
• @Adobe reftex seems to understand \input{tex/10_-_calc} perfectly well? Mar 3, 2015 at 18:50
• Nope: i.imgur.com/cXEZMET.png (the apper window should actually produce ToC) Mar 3, 2015 at 19:17
• @Adobe something strange about your emacs setup then, I just tried reftex-toc on a sample file and the toc shows entries in the file input from a subdirectory. I added an image to my answer Mar 3, 2015 at 20:03

Hmm: the variable reftex-include-file-commands might also be useful, it lists the macro names takes to be including other docs.

• One can't teach reftex-include-file-commands to search for files in particular directory. Mar 5, 2015 at 17:50
• No you are right. It was more a reference to where to add more \include like macro names. I think you should write the people on the auctex mailing list. They are quite helpful. It is probably not them who maintain reftex but they know quite a lot about how it works. Mar 5, 2015 at 18:27