tags:

views:

72

answers:

3

Scenario: I have a main Latex file (main.tex) in which I include a subfile (appendix.tex) using the subfiles package.

Role of appendix.tex: It further includes all the appendices as subfiles kept in an appendix subfolder, so that I just need to include the appendix.tex in the main.tex file.

Current Situation: I have to manually list the appendices in appendix.tex which can be cumbersome to manage.

Target: I want to create a foreach loop kind of thing in the appendix.tex file such that it looks in the appendix subfolder and includes each of the .tex files present in it.

Question: How can this be done?

+1  A: 

Probably easiest done externally via a shell script. Provide some more info on your OS (Win/Apple/Linux) and someone will no doubt provide the necessary script.

cristobalito
I am on Win7 using the proText package for all my latex work. But I guess that should not make a difference, I wish to make the latex file compilable on every machine having latex. so no question of shell script. :)
OrangeRind
I don't think this is possible in just LaTeX - it it is, I'd be extremely interested in how to do it. The following PowerShell script should do the job for you (run in the main folder to generate the appendix.tex):dir .\appendix\*.tex | Split-Path -Leaf | foreach { "\include{$_}" } > appendix.tex
cristobalito
oh, let me try that! :)
OrangeRind
No doubt it can be improved, but hope it works. Probably worth running it before every latex run.
cristobalito
+2  A: 

This can be relatively easy implemented with python.sty from here. This would require you to make sure that the style file and python is available on all machines were you plan to compile this document, but should be more portable than using shell scripts or preprocessors like cpp.

honk
Interesting link
cristobalito
A: 

I did it the other way, with a python pre-processor for LaTeX. My preprocessor generates tables and allows raw python to be put into the LaTeX file. Since python.sty requires that LaTeX be compiled with shell escapes, this may be a better way.

I can post the preprocessor if there is interest.

vy32
It would indeed be interesting to know about such a technique! Is it similar to Honk's answer above? :)
OrangeRind