Last active
October 28, 2019 18:00
-
-
Save Kautenja/853939d7080e36c834d0d657698997e2 to your computer and use it in GitHub Desktop.
LaTeX definitions for including subfiles (.tex, .bib)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% multifile.sty | |
\typeout{A Package for reading subfiles 'multifile' <28 October 2019>} | |
\ProvidesPackage{multifile} | |
\usepackage{subfiles} | |
% a command to run shell commands | |
% USAGE: | |
% \app@exe{<command>} | |
% where: | |
% - <command> is a shell command to run | |
% | |
\makeatletter | |
\def\app@exe{\immediate\write18} | |
\makeatother | |
% a command to include subfiles from a directory. | |
% USAGE: | |
% \subfiles{<directory>} | |
% where: | |
% - <directory> is a directory with .tex files to include alphabetically | |
% | |
\makeatletter | |
\def\subfiles#1{% | |
% list the .tex files in the given directory into a temporary build file | |
\app@exe{for i in `ls -v #1/*.tex`; do echo "\ subfile{$i}" | tr -d "[:space:]" >> \jobname.subfiles.#1.tmp; done} | |
% iterate over the filenames in the temporary file and subfile them | |
\input{\jobname.subfiles.#1.tmp} | |
% delete the temporary file | |
\AtEndDocument{\app@exe{rm -f \jobname.subfiles.#1.tmp}} | |
} | |
\makeatother | |
% a command to include bibliographies from a directory. | |
% USAGE: | |
% \bibliographies{<directory>} | |
% where: | |
% - <directory> is a directory with .bib files to include | |
% | |
\makeatletter | |
\def\bibliographies#1{% | |
% compile all the bibliography files into a single references file | |
\app@exe{find #1 -regex ".*bib" | xargs cat | egrep -v "(\%|^$|^\s*$)" > \jobname.references.bib} | |
% include the compiled bibliography file | |
\bibliography{\jobname.references.bib} | |
} | |
\makeatother |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment