*! version 1.2.1 9dec2016

Title

texmerge -- Merges .tex files into a single .tex file and compiles the new file to .pdf

Syntax

texmerge
input_folder, saveto(output_folder)
[options]

Main
saveto(output_name) output folder

files(filenames) list of files merged; default is for all
.tex files in input_folder to be processed

pre(string) adds text to the beginning of the merged .tex document

post(string) adds text to the end of the merged .tex document

pdflatex if specified .tex file will be compiled using pdflatex

del if specified new .tex file created in input_folder will be deleted

newfile(filename) name of output .tex and .pdf file; default name is "mergedfiles"

Description

texmerge creates a new .tex file in input_folder which merges all inputted .tex files. A .tex
file of the same name will be created in output_folder with additional text provided in pre and
post. If pdflatex is specified the .tex file in output_folder will be compiled using
pdflatex.

Options

Main

saveto(output_folder) specifies that the new .tex and .pdf files will be saved in
output_folder.

files(filenames) restricts processing to specified files. These files must
be located in input_folder. Input should follow the format
"file1.tex file2.tex file3.tex ...". Files will be merged in the order they are
inputted. So text in "file1" will be located at the top of the new file and will be followed by
text in "file2" and so on.

pre(string) adds text in string to the beginning of the merged .tex file. To add multiple lines
of text parse each separate line with "|".

post(string) adds text in string to the end of the merged .tex file. To add multiple lines
of text parse each separate line with "|".

pdflatex specifies that the output .tex file be compiled using pdflatex. The compiled file will
be saved in output_folder.

del removes the outputted merged .tex file from input_folder. This .tex file is created during
processing and includes merged text from all inputted .tex files but does not include additional text
provided by pre and post

newfile gives the name of the new .tex and .pdf files to be created. The default name is "mergedfiles".
filename cannot already exist in either input_folder or output_folder.

Remarks

All inputted .tex files are merged into a single .tex file and saved in input_folder.
In output_folder a new .tex file is created which includes merged text from all inputted .tex files
and includes text provided in pre and post at the beginning and end of the .tex file. If
pdflatex is provided the .tex file in output_folder will be compiled to .pdf.

If files is not specified then the order in which files are merged to the new .tex file is alphabetical.

If neither pre or post options are supplied then no new .tex is created in input_folder but a
merged .tex file will still be created in output_folder and will be compiled to .pdf if pdflatex is
given.

texmerge requires tknz, texcompiler and
appendfile to be installed.

Examples

Example 1: Merging files without compiling

Merge all .tex files located in C:\Users\texfiles to a single .tex file. The files will be
merged in alphabetical order.

. texmerge C:\Users\texfiles, s(C:\Users\output)

. texmerge C:\Users\texfiles, s(C:\Users\output) n(mergedtex.tex)

Merge selected files with text from "file1.tex" apearing before "file2.tex"
in the merged .tex file.

. texmerge C:\Users\texfiles, s(C:\Users\output) n(mergedtex.tex) f(file1.tex file2.tex)

Example 2: Merging files and compiling

Merge all .tex files located in C:\Users\texfiles to a single .tex file. The files will be
merged in alphabetical order. Note that the .tex file will only compile properly if the input
.tex files have the appropriate preamble in the file appearing first in the alphabet and the
appropriate closing lines in the file coming last in the alphabet.

. texmerge C:\Users\texfiles, s(C:\Users\output) pdf

Merge selected files with text from "file1.tex" apearing before "file2.tex"
in the merged .tex file. Note that "file1.tex" must contain the appropriate preamble and
"\end" must be the final line in "file2.tex"

. texmerge C:\Users\texfiles, s(C:\Users\output) n(mergedtex.tex) f(file1.tex file2.tex) pdf

Example 3: Merging files, adding additional text and compiling

Merge all .tex files located in C:\Users\texfiles to a single .tex file with
additional lines added at the beginning and end. Because newfile is not given and del is not specified the
total output will be "mergedfiles.tex" in input_folder, and "mergedfiles.tex" and "mergedfiles.pdf"
in output_folder. "mergedfiles.tex" located in input_folder will not contain the additional
text specified in pre and post.

. local begin "\documentclass[12pt] | \usepackage | \begin"

. local end "\end"

. texmerge C:\Users\texfiles, s(C:\Users\output) pr(`begin') po(`end') pdf

To make clear how the final .tex document will look consider the following example where 2 files are merged.

. local begin "\documentclass[12pt] | \usepackage | \begin"

. local end "\end"

. texmerge C:\Users\texfiles, s(C:\Users\output) pr(`begin') po(`end') f(file1.tex file2.tex) pdf

In this case the final file will look like the following:

\documentclass[12pt]

\usepackage

\being

first line in file1.tex file

second line in file1.tex file

...

final line in file1.tex file

first line in file2.tex file

...

final line in file2.tex file

\end

Author

Iain Snoddy

iainsnoddy@gmail.com