1

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)

Adobe
  • 3,037
  • why use a delimited argument? also why not simply \include{tex/part1} ? – David Carlisle Mar 03 '15 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. – Adobe Mar 03 '15 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. – daleif Mar 03 '15 at 12:20
  • oh in your example usage you are using {10_-_calc} with {..} so why define \includeFromTex with a delimited argument delimited by space? That allows \includeFromTex 10_-_calc but that's not really normal latex syntax and you don't use it anyway. But as it is if you were to use \includeFromTex{10_-_calc}% things would go very wrong as the end of line is required. – David Carlisle Mar 03 '15 at 12:50
  • \begingroup\let\clearpage\relax % tweak that stops include from starting with newpage That is not a tweak it breaks the include system totally and you will get corrupted aux files and incorrect numbering. There is an answer about that on site somewhere. – David Carlisle Mar 03 '15 at 12:53
  • 1
    http://tex.stackexchange.com/questions/108268/redefining-include – David Carlisle Mar 03 '15 at 12:55
  • @DavidCarlisle: do you mean I should use \newcommand instead of \def? – Adobe Mar 03 '15 at 13:39
  • 1
    @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 {} – David Carlisle Mar 03 '15 at 13:43

2 Answers2

2

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}

As mentioned in comments

\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:

enter image description here

David Carlisle
  • 757,742
  • 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. – Adobe Mar 03 '15 at 18:20
  • @Adobe of course you can, why ever not? – David Carlisle Mar 03 '15 at 18:40
  • @Adobe reftex seems to understand \input{tex/10_-_calc} perfectly well? – David Carlisle Mar 03 '15 at 18:50
  • Nope: http://i.imgur.com/cXEZMET.png (the apper window should actually produce ToC) – Adobe Mar 03 '15 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 – David Carlisle Mar 03 '15 at 20:03
1

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

daleif
  • 54,450
  • One can't teach reftex-include-file-commands to search for files in particular directory. – Adobe Mar 05 '15 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. – daleif Mar 05 '15 at 18:27