I want to create LaTeX content which consists of many sections. I will either typeset all of the sections together to get one PDF or typeset each one separately. If they are typeset together, then I want to be able to use label/ref to create links. If they are typeset separately, then I get a link to the relevant PDF instead of the links to the appropriate sections.
I have an OK start, but I am not sure of the next steps. Here is the code:
\documentclass{article}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{a.tex}
\section{a}
\label{a-label}
Text for a
See also \mychoose{(\ref{b-label})}{\url{./only-b.pdf}}
\end{filecontents}
\begin{filecontents}{b.tex}
\section{b}
\label{b-label}
Text for b
See also \mychoose{(\ref{a-label})}{\url{./only-a.pdf}}
\end{filecontents}
\begin{filecontents}{only-a.tex}
\documentclass{article}
\usepackage{hyperref}
\newcommand\mychoose[2]{#2}
\begin{document}
\input a.tex
\end{document}\end
\end{filecontents}
\begin{filecontents}{only-b.tex}
\documentclass{article}
\usepackage{hyperref}
\newcommand\mychoose[2]{#2}
\begin{document}
\input b.tex
\end{document}\end
\end{filecontents}
\begin{filecontents}{together.tex}
\documentclass{article}
\usepackage{url}
\newcommand\mychoose[2]{#1}
\begin{document}
\input a.tex
\input b.tex
\end{document}\end
\end{filecontents}
\end{document}\end
Typeset it once to see the files a.tex, b.tex, only-a.tex, only-b.tex and together.tex.
This allows me to create the document with the two sections (by typesetting together.tex). I can create the document consisting of just section "a" (by typesetting only-a.tex). The url command does not work. Also, there is a lot of typing involved to use the mychoose command as demonstrated above. Suggestions welcome!
NOTES:
- The files "a.tex" and "b.tex" are similar (and there differences are easy to see).
- The files "together.tex", "only-a.tex" and "only-b.tex" are similar (and their differences are involve different number of input commands and #1 vs #2).
- I can create the "only-" documents using a computer program and so am not concerned about the duplication.
Better ideas are welcome.
Thanks, Mark
\endcomments in theonly-...filecontentsenvironments, but they will be ignored, since they occur after\end{document}. You could use a common preamble.styfile for all documents there, even with\begin{filecontents}{mycommon.sty}....\end{filecontents}etc. where you hold some of the commands. – Jul 05 '15 at 02:04docmutewhich I used to produce either a master file or individual files. This question with my answer is an example of using 'docmute'. http://tex.stackexchange.com/questions/245138/is-there-any-way-to-read-arbitrary-part-of-external-tex-file/245146#245146 – R. Schumacher Jul 05 '15 at 02:36