Tuesday, March 2, 2010

Create Section Headers with TexShop and Applescript

I really like the macro feature of TexShop. One of the most common use cases of macros would probably be the definition of a section (or subsection etc.). My section-creation-macro has been quite simple in the past:

% ----------------------------------------
% \section{#SEL##INS#}
% \label{sec:#SEL#}
% ----------------------------------------
This small snippet creates a nicely formatted section header including a label. However, there's a really annoying problem: When creating a reference to a section (that is, to its label), TeXShop does not handle spaces accordingly when selecting a label from the dropdown list. For example, if your label is something like \label{sec:Hello World}, the complete label is shown in the list, but only \ref{sec:Hello} is inserted into the text. In order to overcome this problem, I always replace spaces in labels with underscores. So my label would be "sec:Hello_World", and TeXShop is working perfectly. But replacing spaces with underscores by hand is even more annoying. So I replaced my section macro with an applescript version:

--Applescript direct

-- Create a section header from selected text. A label is automatically added with a prefix
-- "sec:", spaces are converted to underscores.
-- (C) 2010 Jens von Pilgrim

property level : "section"
property cmtchar : "-"
property cmtlength : 78
property labelprefix : "sec:"
-- property newline: "\n"
tell application "TeXShop"
 
 
 tell application "TeXShop" to set title to the content of the selection of the front document
 
 set new_title to title
 if ((count of the paragraphs of title) ≥ 1) then
  set this_line to paragraph 1 of title
  set label to this_line
  set add to "true"
  
  -- replace commands
  set label to do shell script ¬
   "echo " & the quoted form of label & ¬
   " | sed -E 's/([[:space:]]|[[:punct:]])/_/g'"
  
  set comment to "% "
  repeat with ii from 1 to cmtlength
   set comment to comment & cmtchar
  end repeat
  
  set new_title to ¬
   comment & return & ¬
   "\\" & level & "{" & title & "}" & return & ¬
   "\\label{" & labelprefix & label & "}" & return & ¬
   comment & return
 end if
 
 tell application "TeXShop" to set the selection of the front document to new_title
end tell
This macro creates a section just like the initial macro version, but this time spaces are automatically replaced in the label. That is, simply select your section title, activate the macro, and you get a nicley formatted title with a TeXShop compatible label. E.g. Mark
Hello World, this is great
and the macro will convert this to
% ==============================================================================
\section{Hello World, this is great}
\label{sec:Hello_World__this_is_great}
% ==============================================================================
You can easily adjust the macro in order to create subsection, subsubsections or chapters as well. I have different kind of comments for different section levels, all you have to change are the properties in the first line:

...
property level : "section"
property cmtchar : "-"
property cmtlength : 78
property labelprefix : "sec:"
...
Change level to "subsection" or whatever, and set the cmtchar to "*", "." or whatever you like. Changing a section level has already been subject of another blog post: Increase/Decrease Section Level with TeXShop Macros.

Friday, January 29, 2010

OmniGraffle and multi-language diagrams

Sometimes I need diagrams in different languages for different purposes. E.g., for presentations on international conferences, I use english labels, while I need german labels for my thesis (which is written in German). I sometimes change my diagrams, I don't want to have two version of a diagram, one in english, another one in german. Because I always export my diagrams to PDF, I'm using two smart export scripts in conjunction with layers, used for internationalization (i18n). First of all, I add a layer for each language. In order to distinguish these internationalization layers from other layers, I use a prefix "lang_". All language specific labels and elements are added to that layer. Other things are placed on layers without my language prefix. Usually, I initially create the diagram in one language, and then move all language specific stuff to the language layer. I then copy all that language specific stuff and paste it onto another language layer (or, simply duplicate the layer), where it is translated. By changing the visibility of the language layers, I can change the language of the diagram. Since it is one diagram, changes on the shared layer are reflected in all language versions, language dependant things have to be adjusted (and translated) manually. The following screenshots show a sample diagram with three layers for shared, english and german elements. In order to create language specific PDFs, I have modified a script I published here some time ago. Here is the modified version:
-- converts selected OmniGraffle files to PDF with internationalization -- based on Greg Titus's script found at -- http://forums.omnigroup.com/showthread.php?t=106&highlight=export+applescript -- -- by jevopi, 2010 global export_language, layer_prefix set export_language to "de" set layer_prefix to "lang_" tell application "Finder" set these_items to the selection end tell repeat with i from 1 to the count of these_items set this_item to (item i of these_items) as alias set this_info to info for this_item -- insert actions here for: this_item set item_path to POSIX path of this_item set item_folder to (parent of (item i of these_items)) as string set item_name to name of (item i of these_items) set item_ext to name extension of (item i of these_items) set exp_name to my rename(item_name, item_ext, "pdf") set exp_path to item_folder & exp_name set msg to "Path: " & item_path & ", Exp: " & exp_path --display dialog msg buttons {"OK"} default button 1 my omniConvert(this_item, item_path, exp_path) end repeat -- this sub-routine just comes up with the new name on rename(item_name, item_ext, new_extension) tell application "Finder" if the item_ext is "" then set the trimmed_name to the file_name else set the trimmed_name to text 1 thru -((length of item_ext) + 2) of the item_name end if set target_name to (the trimmed_name & "_" & export_language & "." & new_extension) as string end tell return the target_name end rename -- this sub-routine does the export on omniConvert(source_file, source_path, target_path) with timeout of 900 seconds tell application "OmniGraffle Professional 5" -- save the current export settings so we can replace them later set oldAreaType to area type of current export settings set oldBorder to include border of current export settings set oldBackground to draws background of current export settings -- here is where you set the export settings you want set area type of current export settings to all graphics set include border of current export settings to false set draws background of current export settings to false set export scale of current export settings to 1 set border amount of current export settings to 0 -- open the file if it isn't already open set needToOpen to (count (documents whose path is source_path)) is 0 if needToOpen then open source_file end if -- do the export set docsWithPath to documents whose path is source_path set theDoc to first item of docsWithPath set allLayers to layers of first canvas of the theDoc repeat with i from 1 to the count of allLayers set theLayer to (item i of allLayers) -- repeat with theLayer in layers of first canvas of theDoc set theName to name of theLayer if (offset of layer_prefix in theName) > 0 then if theName = layer_prefix & export_language then set visible of theLayer to true else set visible of theLayer to false end if end if end repeat save theDoc in file target_path -- if the file wasn't already open, close it again if needToOpen then close theDoc saving no end if -- put the original export settings back set area type of current export settings to oldAreaType set include border of current export settings to oldBorder set draws background of current export settings to oldBackground end tell end timeout end omniConvert
This script exports an OmniGraffle diagram to PDF. Besides, only one language specific layer is made visible and the langauge id is added to the filename. The language is defined in line
set export_language to "de"
That is, this script automatically creates a german version of the diagram. I have a script for each language (and one w/o i18n) in my script folder, e.g. After applying the both i18n-scripts to the diagram, two PDFs are created from my diagram: This technique works pretty well with text and connection labels. Unfortunately labels placed on shapes cannot be moved on a layer different from the shape. So, in these cases you have to move the whole shape to the language layer. If you translate a diagram after you have created it, this works pretty well. It may become a little bit annoying if you have to change the diagram, but at least you are aware of the changes and don't have to work with two separate files.

Sunday, September 20, 2009

Acronyms and LaTeX

Computer geeks like acronyms, especially three-letter acronyms (TLAs). To give you an impression: I'm working in the area of MDD. Actually, OMG calls it MDA, Stuart Kent MDE, and others MDSD. In short, models, such as UML or EMF models, are transformed into other models or code by M2M- or M2T-transformations, such as QVT or ATL. Writing a thesis in that area is really hard, since you have to keep an eye on all that TLAs. So I've looked for a LaTeX package doing the job for me, and what I found is a package called acronym by Tobias Oetiker. I really like the simplicity of this package, this is why I decided to use that instead of other alternative solutions.

Install acronym

Surprisingly, it was already installed with my tex installation (gwTeX), but it requires a packages called suffix, which was not. The later is contained in a bundle called bigfoot. Here are the CTAN locations of acronym and bigfoot: In order to install a package from the files available at CTAN, you usually have to
  • download the zip or all the files from CTAN
  • unzip them (or put them into a folder) and put the folder somewhere tex can find it, e.g. into $HOMETEXMF (i.e. ~/library/texmf/tex)
  • run the installer via latex *.ins, in that case latex bigfoot.tex
Now you are ready to use acronym. It is quite simple: simply include the package via
\usepackage{acronym}
Instead of simply writing the acronym in your text, you now have to write \ac{..} (or, in case of a plural, \acp{..}). You have to add a new environment with a list of all the acronyms and their long form with

\begin{acronym}
\arcro{..}{...}
\end{acronym}
The first time an acronym is used, \ac prints the long form with the acronym in brakets. There are also some other commands available, see the acronym documentation for details.

Add list of acronyms to table of contents

Unfortunately, there is no command available for adding an entry to the table of contents. I have written my own command for that, which creates an entry similar to the list of figures. You have to add the following code somewhere in your preamble:

\@ifundefined{listofacronymsname}{\newcommand{\listofacronymsname}{Acronyms}}{}
\@ifundefined{chapter}{%
\newcommand{\listofacronyms}{%
\section*{\listofacronymsname}%
\addcontentsline{toc}{section}{\listofacronymsname}%
\label{sec:acronyms}%
\markboth{\listofacronymsname}{\listofacronymsname}%
}}{%
\newcommand{\listofacronyms}{%
\chapter*{\listofacronymsname}%
\addcontentsline{toc}{chapter}{\listofacronymsname}%
\label{sec:acronyms}%
\markboth{\listofacronymsname}{\listofacronymsname}%
}}
It defines two commands:
\listofacronymsname
defines the name of the heading used for the list of acronyms. It is "Acronyms" by default, but you can change that with \renewcommand, as demonstrated below.
\listofacronyms
creates a heading and a section or chapter definition (depending on the document class), which is also added to the table of contents. A label "sec:acronyms" is added as well.
(Update 2012-05-21: \markboth adjusts the header accordingly, see mrunix thread)

Put it all together

Let's put it all together. Firstly, we use the package and define the \listofacronyms command:

\usepackage[printonlyused,smaller]{acronym}     % acronyms ac
\@ifundefined{listofacronymsname}{\newcommand{\listofacronymsname}{Acronyms}}{}
...
I have added some parameters to only list the used acronyms and use a slightly smaller font. Secondly, we create a new file "acronyms.text" with a list of the acronyms, which makes it easier to maintain. This is how my file looks like:

\renewcommand{\listofacronymsname}{Abkürzungsverzeichnis} % german title
\listofacronyms

% \acro{acronym}[shortname]{fullname}
% inside fullname: \acroextra{} -- not in text, only in description list
\begin{acronym}
\acro{EMF}{Eclipse Modeling Framework \cite{EMF}}
\acro{GEF}{Graphical Editing Framework \cite{GEF}}
\acro{MDD}{Model Driven Development}
\acro{MDA}{Model Driven Architecture}
\acro{UML}{Unified Modeling Language}
...
\end{acronym}
The acronyms are not sorted automatically, I use SubEthaEdit for sorting the acronyms from time to time, but I guess there are several editors which can do that. This file has to be included in your main latex source document, e.g.,

\begin{appendix}
\input{acronyms}
\end{appendix}
Last but not least, we have to use the acronym commands in the text, just like that:

I'm working in the area of \ac{MDD}. Actually, \ac{OMG} calls it \ac{MDA}, Stuart Kent \ac{MDE}. In short, models, such as \ac{UML} or \ac{EMF} models, ...
You do not have to look for the first usage of an acronym anymore, acronym is doing that for you. If you forget to define an acronym, you will see that in the generated output as acronym creates a bold placeholder in that case. If you do not want to printed the list of acronyms, you can use acronym just as described before, you only have to add a package option nolist (i.e. \usepackage[nolist]{acronym}). This is especially useful in combination with the option footnote, as in that case the description of the acronym is printed as a footnote and not in the text (and one can find the definitions by scanning the footnotes, which is ok for shorter texts). Thank you very much, Tobias Oetiker, for writing that package!

Wednesday, July 22, 2009

OmniGraffle Stencils

My favorite application for creating nice drawing is OmniGraffle. At Graffletopia you can find lots of user created stencils, that is templates for using in your own drawing. The latest version of OmniGraffle let you search a stencil directly at Graffletopia, so if you think you need something like UML notation elements, just enter UML in OmniGraffel's stencil window and you will find several stencils at Graffletopia. I have created some stencils as well, and you can download them from Graffletopia. You can either search for them from within OmniGraffle, or you can download and install them manually. Here is a list of my stencils:
  • UML 2.1 Collection: A collection of notation elements for creating UML 2 class, activity, use case, sequence, or component diagrams. It's a rather large stencil, but it contains most UML 2.1 elements
  • Feature Diagrams: Feature Diagram stencil, notation based on the book "Generative Programming" by K. Czarnecki and U.W. Eisenecker. (Updated today and fixed some problems)
  • Post-it Notes: A collection of six colored post-it notes with nice shadow, slightly bended.
Have fun!

Thursday, July 16, 2009

Increase/Decrease Section Level with TeXShop Macros

TeXShop is a really nice editor, especially since new commands can be added using macros. These macros can contain AppleScript, which makes them very flexible and powerful. I like formating my headings in order to easily see sections, subsections etc. For that reason, I have added some macros creating sections etc. like this: Macro "section":

% ==============================================================================
\section{#SEL##INS#}
\label{sec:#SEL#}
% ==============================================================================
My latex code then looks like that:

% ******************************************************************************
\chapter{Chapter}
\label{chapter:Chapter}
% ******************************************************************************

% ==============================================================================
\section{Section}
\label{sec:Section}
% ==============================================================================

% ------------------------------------------------------------------------------
\subsection{SubSection}
\label{sec:SubSection}
% ------------------------------------------------------------------------------

% ..............................................................................
\subsubsection{SubSubSection}
\label{sec:SubSubSection}
% ..............................................................................

\paragraph{Paragraph}
This works pretty well. But it becomes very painful to change a section to a subsection, because I do not only want to change "section" to "subsection", but the comment lines as well. So I added two macros including AppleScript in order to decrease or increase the level of a section. I assume other people might find these macros useful, so I publish them here. They are written very quick and dirty, so you may have to adapt them to suit your preferences: Macro: "Decrease Section Level":

--Applescript direct

-- Decrease Section Level
--Select Section Block including Comments to decrease section level, i.e. section become subsection, chapter becomes section and so on

-- (C) 2009 Jens von Pilgrim

--THE SCRIPT:

property texapp : "TeXShop"
tell application texapp
 
 if texapp = "TeXShop" then
  tell application "TeXShop" to set section to the content of the selection of the front document
 else if texapp = "iTeXMac" then
  --tell application "iTeXMac" to set section to (the selection of the text of the front document)
 end if
 
 set new_section to ""
 repeat with ii from 1 to the count of the paragraphs of section
  
  set this_line to paragraph ii of section
  set new_line to this_line 
  set add to "true"

  -- replace commands
  if this_line contains "\\chapter" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\chapter/\\\\section/'"
  end if
  if this_line contains "\\section" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\section/\\\\subsection/'"
  end if
  if this_line contains "\\subsection" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\subsection/\\\\subsubsection/'"
  end if
  if this_line contains "\\subsubsection" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\subsubsection/\\\\paragraph/'"
  end if

  -- replace the comments
  if this_line contains "% ******************************************************************************" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\*/=/g'"
  end if
  if this_line contains "% ==============================================================================" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/=/-/g'"
  end if
  if this_line contains "% ------------------------------------------------------------------------------" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/-/\\./g'"
  end if
  if this_line contains "% .............................................................................." then
   set add to "false"
  end if

  if add="true" then
   if new_section = "" then
    set new_section to new_line
   else
    set new_section to new_section & return & new_line
   end if
  end if  
  
 end repeat
 
 if texapp = "TeXShop" then
  tell application "TeXShop" to set the selection of the front document to new_section
 else if texapp = "iTeXMac" then
  --tell application "iTeXMac" to insert new_section in the text of the front document
 end if
end tell
Macro: "Increase Section Level":

--Applescript direct

-- Increase Section Level
--Select Section Block including Comments to decrease section level, i.e. section become subsection, chapter becomes section and so on

-- (C) 2009 Jens von Pilgrim
--THE SCRIPT:

property texapp : "TeXShop"
tell application texapp
 
 if texapp = "TeXShop" then
  tell application "TeXShop" to set section to the content of the selection of the front document
 else if texapp = "iTeXMac" then
  --tell application "iTeXMac" to set section to (the selection of the text of the front document)
 end if
 
 set new_section to ""
 repeat with ii from 1 to the count of the paragraphs of section
  
  set this_line to paragraph ii of section
  set new_line to this_line 
  set add to "true"

  -- replace commands
  if this_line contains "\\section" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\section/\\\\chapter/'"
  end if
  if this_line contains "\\subsection" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\subsection/\\\\section/'"
  end if
  if this_line contains "\\subsubsection" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\subsubsection/\\\\subsection/'"
  end if
  if this_line contains "\\paragraph" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\\\paragraph/\\\\subsubsection/'"
   set new_line to "% .............................................................................." & return & new_line & return & "% .............................................................................."
  end if

  -- replace the comments
  if this_line contains "% ==============================================================================" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/=/\\*/g'"
  end if
  if this_line contains "% ------------------------------------------------------------------------------" then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/-/=/g'"
  end if
  if this_line contains "% .............................................................................." then
   set new_line to do shell script ¬
    "echo " & the quoted form of this_line & ¬
    " | sed 's/\\./-/g'"

  end if

  if add="true" then
   if new_section = "" then
    set new_section to new_line
   else
    set new_section to new_section & return & new_line
   end if
  end if  
  
 end repeat
 
 if texapp = "TeXShop" then
  tell application "TeXShop" to set the selection of the front document to new_section
 else if texapp = "iTeXMac" then
  --tell application "iTeXMac" to insert new_section in the text of the front document
 end if
 
end tell
These two macros increase or decrease the level of a section. You have to simply select a section (or several sections), and the levels of all chapters, sections, and paragraphs are increased or decreased respectively. Besides the commands, the comments are reformatted as well. When increasing the levels, the following modifications are made:
  1. section -> chapter
  2. subsection -> section
  3. subsubsection -> subsection
  4. paragraph -> subsubsection
When decreasing the levels, the following modifications are made:
  1. chapter -> section
  2. section -> subsection
  3. subsection -> subsubsection
  4. subsubsection -> paragraph
Note that chapters are not increased any further, and paragraphs are not decreased.

Wednesday, July 15, 2009

How to write very long documents with LaTeX

I eventually started writing my thesis--with LaTeX. Since it will become a rather long document (approx. 200 pages) I decided to split the document into its chapters (and maybe into more parts). Splitting a document is very easy with latex and it typically looks like that:

\documentclass{someClass}
... some definitions, use packages etc ...
\begin{document}
...
\maketitle
...
\input{abstract}
\input{introduction}
...
\input{relatedwork}
\input{conclusion}
...
\end{document}
This works pretty well, and I always use this pattern for writing smaller papers. Unfortunately I found two severe problems:
  1. The latex compiler is unaware of folders.
  2. I cannot compile the parts separately, which leads to new problems

Chapterfolder

The first problem is further described and solved by the latex package "chapterfolder". Instead of simply including a chapter, it is included and the current folder is changed accordingly. The main file will now look like this:

...
\begin{document}
...
\maketitle
...
\cfchapter{Introduction}{chapters/introduction}{introduction.tex}
...
\cfchapter{Conclusion}{chapters/conclusion}{conclusion.tex}
In my case I can now use chapter-relative figure folders, i.e. my folder structure looks like that:

/Main
- main.tex
+ chapters
 + introduction
     - introduction.tex
     + fig
         - figOfChapter1.png
+ conclusion
     - conclusion.tex
     + fig
         - figOfChapter2.png
Without "chapterfolder", I had to include a figure in chapter 1 (Introduction) like this:
\includegraphics{chapters/introduction/fig/figOfChapter1}
However, I want to be able to simply include figures by specifying a relative path to the chapter document, that is
\includegraphics{fig/figOfChapter1}
In order to achieve, this, we have to rewrite the includegraphics command. We can do that in the preamble, next to the usepackage statement:
\usepackage{chapterfolder}
% and we re-write includegraphics
\let\includegraphicsWithoutCF\includegraphics
\renewcommand{\includegraphics}[2][]{\includegraphicsWithoutCF[#1]{\cfcurrentfolder#2}}
This makes life much easier, especially if figures are moved from one chapter to another (I have only to move the file of the figure and can simply copy the code). And we are also able of compiling documents separately, as explained further on!

Compile Separately and Embedded

Although I'm using a wonderful LaTeX editor (Texshop) and my computer is pretty fast, working with a split document has some tradeoffs:
  1. The "goto error" function in my editor is not working with included documents, which makes bug fixing really annoying.
  2. Compiling a (currently) 100 page long document with lots of images takes quite some time
For that reason, I tried to figure out how to split my document and use a main file including all parts, while at the same time the parts could be compiled standalone. Here is my solution: In the main file, I define a command for letting the included files know that they are embedded:

\newcommand{\isEmbedded}{true}
In my parts (chapters), I can now test whether this command is defined or not, and include a preamble if required:

\ifx\isEmbedded\undefined
..
\documentclass{../../styles/myStyle}
..
other settings
...
\begin{document}
\maketitle
...
% -------+---------+---------+---------+---------+---------+---------+---------+
\else
\fi
% ******************************************************************************

Here comes the text of the chapter or part.

% ******************************************************************************
\ifx\isEmbedded\undefined
\bibliography{myBib}
...
\end{document}
\else
\fi
I can now compile every chapter separately, and finding a bug is very simple thanks to Texshops "Goto Error" function -- which is now working. Without any modifications, I can also compile the whole text, i.e. my main.tex file.

Tuesday, November 6, 2007

Merge PDF documents with LaTeX

Sometimes, a single book comes in multiple PDF documents, one document for a chapter. I often want to merge these PDF document into one single document. There are several possibilites, e.g. using Adobe Acrobat. A less expensive and yet easy solution is to use LaTeX for that purpose. So I have created a simple LaTeX template in which I only have to add the names of the documents to be merged., that's it. Besides, several options are available such as scaling the documents on the fly. The work is done by the LaTex package "pdfpages", see pdfpages at www.ctan.org. The documents are included with \includepdf, the two lines above this command are used here for creating a table of content in the PDF.

%!TEX encoding = UTF-8 Unicode
% -------+---------+---------+---------+---------+---------+---------+---------+
\documentclass{book}
% -------+---------+---------+---------+---------+---------+---------+---------+
% Used Packages
% -------+---------+---------+---------+---------+---------+---------+---------+
\usepackage[pdftex,dvips]{graphicx}
\usepackage[english]{babel}
\usepackage[
 pdfhighlight=/O, colorlinks, linkcolor=black, urlcolor=black, citecolor=black,
 breaklinks, bookmarksopen,bookmarksopenlevel=1,linktocpage
] {hyperref}
\usepackage{fancyhdr}
\usepackage{pdfpages} % That does the trick!
% -------+---------+---------+---------+---------+---------+---------+---------+
% Header
% -------+---------+---------+---------+---------+---------+---------+---------+
\pagestyle{headings}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
%\fancyfoot[LE,RO]{\raisebox{-25mm}{\large\textsf{\thepage}}}
%\fancyfoot[RE,LO]{\raisebox{-25mm}{Merged Document}}
%\fancyfoot[CE,CO]{\raisebox{-25mm}{}}
\renewcommand{\headrulewidth}{0mm}
\renewcommand{\footrulewidth}{0mm}
% -------+---------+---------+---------+---------+---------+---------+---------+
% Settings for including the PDF documents,
% see: 
% http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages/pdfpages.pdf
% -------+---------+---------+---------+---------+---------+---------+---------+
\includepdfset{pages=-,nup=1x1, pagecommand={\mbox{}}}
% -------+---------+---------+---------+---------+---------+---------+---------+
% The Documents
% -------+---------+---------+---------+---------+---------+---------+---------+
\begin{document}

\phantomsection 
\addcontentsline{toc}{chapter}{Chapter 1}
\includepdf{file1.pdf}

\phantomsection 
\addcontentsline{toc}{chapter}{Chapter 2}
\includepdf{file2.pdf}

% ...

% -------+---------+---------+---------+---------+---------+---------+---------+
\end{document}