General ⇒ including text from a "source" file
including text from a "source" file
I want to have some sort of source file with a punch of blocks of text, each with a label. Then I would like to be able to make a .tex file and just say to include some subset of these blocks of text (not plain text, I want to be able to include almost arbitrary sets of Latex commands in the blocks) just by listed up the label names.
In other words, I would like to be able to maintain a "master document" that I can easily take pieces of in whatever combination I want in new documents.
Is there something available to do this, or is it easy to do from scratch myself?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Re: including text from a "source" file
Re: including text from a "source" file
\begin{block}{label 1}
latex code goes here
\end{block}
\begin{block}{label 2}
latex code goes here
\end{block}
Then in my latex file I could do something like:
\includeblock{label 1}
And then that would be replaced on processing by everything in the label 1 block of code. I assume I would need to process several times to then process the new code that got added.
Something roughly like that.
Re: including text from a "source" file
I thought I might be able to use the probsoln package to do this, but there seemed to be problems integrating the two in the way I need. I need to have the \question command associated with a particular problem in the database of problems since it includes special information about the number and type of points for the problem (there are different types of points, which is why I had to customize the files).
So I'm trying to figure out another way to do this. I figured there might be a very general way to do this, which might even be useful for other projects I may use in the future.
including text from a "source" file
try something like the following:
Code: Select all
\newsavebox\scratchbox
\newcommand*\includeblocklabel{}
\newcommand*\blocklabel{}
\newif\ifincludeblock
\newcommand*\includeblock[1]{%
\renewcommand*\includeblocklabel{#1}%
\input{masterfile.tex}%
}
\newenvironment{block}[1]{%
\renewcommand*\blocklabel{#1}%
\ifx\blocklabel\includeblocklabel
\includeblocktrue
\else
\includeblockfalse
\begin{lrbox}{\scratchbox}%
\fi
}{%
\ifincludeblock\else
\end{lrbox}%
\fi
}
Re: including text from a "source" file
Re: including text from a "source" file
Re: including text from a "source" file
including text from a "source" file
Code: Select all
%% masterfile.tex:
\begin{block}{abc}
ABC
\end{block}
\begin{block}{def}
DEF
\end{block}
\begin{block}{ghi}
GHI
\end{block}
%% some other file:
\documentclass{article}
\newsavebox\scratchbox
\newcommand*\includeblocklabel{}
\newcommand*\blocklabel{}
\newif\ifincludeblock
\newcommand*\includeblock[1]{%
\renewcommand*\includeblocklabel{#1}%
\input{masterfile.tex}%
}
\newenvironment{block}[1]{%
\renewcommand*\blocklabel{#1}%
\ifx\blocklabel\includeblocklabel
\includeblocktrue
\else
\includeblockfalse
\begin{lrbox}{\scratchbox}%
\fi
}{%
\ifincludeblock\else
\end{lrbox}%
\fi
}
\begin{document}
\includeblock{ghi}
\includeblock{abc}
\end{document}