CMakeUserUseLATEX: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
[[CMake_User_Contributed_Macros|Back]] | [[CMake_User_Contributed_Macros|Back]] | ||
Compiling LaTeX files into readable documents is actually a very involved process. Although CMake comes with FindLATEX.cmake, it does nothing for you other than find the commands associated with LaTeX. I like using CMake to build my LaTeX documents, but creating targets to do it is actually a pain. Thus, I've compiled a bunch of macros that help me create targets in CMake into a file I call "UseLATEX.cmake". Here are some of the things UseLATEX.cmake handles: | =Description= | ||
Compiling LaTeX files into readable documents is actually a very involved process. Although CMake comes with FindLATEX.cmake, it does nothing for you other than find the commands associated with LaTeX. I like using CMake to build my LaTeX documents, but creating targets to do it is actually a pain. Thus, I've compiled a bunch of macros that help me create targets in CMake into a file I call "[[CMakeUserUseLATEX_UseLATEX.cmake| UseLATEX.cmake]]". Here are some of the things UseLATEX.cmake handles: | |||
* Runs LaTeX multiple times to resolve links. | * Runs LaTeX multiple times to resolve links. | ||
Line 7: | Line 9: | ||
* Runs configure on your latex files to replace @VARIABLE@ with the equivalent CMake variable. | * Runs configure on your latex files to replace @VARIABLE@ with the equivalent CMake variable. | ||
* Automatically finds png and eps files and converts them to formats latex and pdflatex understand. | * Automatically finds png and eps files and converts them to formats latex and pdflatex understand. | ||
=Download= | |||
Click here to get a copy of [[CMakeUserUseLATEX_UseLATEX.cmake| UseLATEX.cmake]]. | |||
=Usage= | |||
Using [[CMakeUserUseLATEX_UseLATEX.cmake| UseLATEX.cmake]] is easy. For a basic LaTeX file, simply include the file in your CMakeLists.txt and use the <tt>ADD_LATEX_DOCUMENT</tt> command to make targets to build your document. For an example document in the file MyDoc.tex, you could establish a build with the following simple CMakeLists.txt. | |||
PROJECT(MyDoc NONE) | |||
INCLUDE(UseLATEX.cmake) | |||
ADD_LATEX_DOCUMENT(MyDoc.tex NONE NONE) | |||
==Using a Bibliography== | |||
For any technical document, you will probably want to maintain a bibtex database of papers you are referencing in the paper. You can incorporate your .bib file by adding it as the third argument to the <tt>ADD_LATEX_DOCUMENT</tt> command. | |||
ADD_LATEX_DOCUMENT(MyDoc.tex NONE MyDoc.bib) | |||
This will automatically add targets to build your bib file and link it into your document. To use the bibtex file in your LaTeX file, just do as you normally would with <tt>\cite</tt> commands and bibliography commands: | |||
\bibliographystyle{plain} | |||
\bibliography{ParallelVolumeRenderingInParaView} | |||
==Incorporating Images== | |||
To be honest, incorporating images into LaTeX documents can be a real pain. This is mostly because the format of the images needs to depend on the version of latex you are running (latex vs. pdflatex). With these CMake macros, you only need to convert your raster graphics to png format and your vector graphics to eps format. Place them all in a common directory (e.g. images) and then use the <tt>ADD_LATEX_IMAGES</tt> and <tt>ADD_LATEX_DOCUMENT</tt> macros to point to them. | |||
ADD_LATEX_IMAGES(images) | |||
ADD_LATEX_DOCUMENT(MyDoc.tex . MyDoc.bib) | |||
Alternatively, you could add a CMakeLists.txt file to the images directory and call <tt>ADD_LATEX_IMAGES(.)</tt> to that directory. In that case, in the root directory you would add a <tt>SUBDIRS</tt> command to the root CMakeLists.txt and change the second argument of the <tt>ADD_LATEX_DOCUMENT</tt> command to <tt>images</tt>. | |||
Once you establish the images directory, CMake will automatically find all png and eps files in it and add makefile targets to use Image Magick's convert to convert the file times to those appropriate for the build. CMake will also give you a LATEX_SMALL_IMAGES options that, when on, will downsample raster images. This can help speed up building and viewing documents. It will also make the output image sizes smaller. | |||
One more note about raster graphics. Encapsulated postscript (eps) files have a bounding box that is often lost when converting to pdf types. When using eps files, it is best to search for a line starting with <tt>%%BoundingBox:</tt> such as | |||
%%BoundingBox: 58 77 734 536 | |||
and then copy these numbers to the <tt>bb</tt> option of the LaTeX <tt>\includegraphics</tt> command: | |||
\includegraphics[width=\linewidth,bb=58 77 734 536] | |||
==Making an Index== | |||
You can make an index in a LaTeX document by using the makeidx package. However, this package requires you to run the makeindex command. If you set <tt>LATEX_USE_INDEX</tt> to a true value before calling <tt>ADD_LATEX_DOCUMENT</tt>, makeidx will automatically be added to the build. | |||
ADD_LATEX_IMAGES(images) | |||
SET(LATEX_USE_INDEX 1) | |||
ADD_LATEX_DOCUMENT(MyDoc.tex . MyDoc.bib) | |||
[[CMake_User_Contributed_Macros|Back]] | [[CMake_User_Contributed_Macros|Back]] | ||
{{CMake/Template/Footer}} |
Revision as of 21:14, 13 December 2005
Description
Compiling LaTeX files into readable documents is actually a very involved process. Although CMake comes with FindLATEX.cmake, it does nothing for you other than find the commands associated with LaTeX. I like using CMake to build my LaTeX documents, but creating targets to do it is actually a pain. Thus, I've compiled a bunch of macros that help me create targets in CMake into a file I call " UseLATEX.cmake". Here are some of the things UseLATEX.cmake handles:
- Runs LaTeX multiple times to resolve links.
- Can run bibtex and makeindex to make bibliographies and/or indexes.
- Runs configure on your latex files to replace @VARIABLE@ with the equivalent CMake variable.
- Automatically finds png and eps files and converts them to formats latex and pdflatex understand.
Download
Click here to get a copy of UseLATEX.cmake.
Usage
Using UseLATEX.cmake is easy. For a basic LaTeX file, simply include the file in your CMakeLists.txt and use the ADD_LATEX_DOCUMENT command to make targets to build your document. For an example document in the file MyDoc.tex, you could establish a build with the following simple CMakeLists.txt.
PROJECT(MyDoc NONE) INCLUDE(UseLATEX.cmake) ADD_LATEX_DOCUMENT(MyDoc.tex NONE NONE)
Using a Bibliography
For any technical document, you will probably want to maintain a bibtex database of papers you are referencing in the paper. You can incorporate your .bib file by adding it as the third argument to the ADD_LATEX_DOCUMENT command.
ADD_LATEX_DOCUMENT(MyDoc.tex NONE MyDoc.bib)
This will automatically add targets to build your bib file and link it into your document. To use the bibtex file in your LaTeX file, just do as you normally would with \cite commands and bibliography commands:
\bibliographystyle{plain} \bibliography{ParallelVolumeRenderingInParaView}
Incorporating Images
To be honest, incorporating images into LaTeX documents can be a real pain. This is mostly because the format of the images needs to depend on the version of latex you are running (latex vs. pdflatex). With these CMake macros, you only need to convert your raster graphics to png format and your vector graphics to eps format. Place them all in a common directory (e.g. images) and then use the ADD_LATEX_IMAGES and ADD_LATEX_DOCUMENT macros to point to them.
ADD_LATEX_IMAGES(images) ADD_LATEX_DOCUMENT(MyDoc.tex . MyDoc.bib)
Alternatively, you could add a CMakeLists.txt file to the images directory and call ADD_LATEX_IMAGES(.) to that directory. In that case, in the root directory you would add a SUBDIRS command to the root CMakeLists.txt and change the second argument of the ADD_LATEX_DOCUMENT command to images.
Once you establish the images directory, CMake will automatically find all png and eps files in it and add makefile targets to use Image Magick's convert to convert the file times to those appropriate for the build. CMake will also give you a LATEX_SMALL_IMAGES options that, when on, will downsample raster images. This can help speed up building and viewing documents. It will also make the output image sizes smaller.
One more note about raster graphics. Encapsulated postscript (eps) files have a bounding box that is often lost when converting to pdf types. When using eps files, it is best to search for a line starting with %%BoundingBox: such as
%%BoundingBox: 58 77 734 536
and then copy these numbers to the bb option of the LaTeX \includegraphics command:
\includegraphics[width=\linewidth,bb=58 77 734 536]
Making an Index
You can make an index in a LaTeX document by using the makeidx package. However, this package requires you to run the makeindex command. If you set LATEX_USE_INDEX to a true value before calling ADD_LATEX_DOCUMENT, makeidx will automatically be added to the build.
ADD_LATEX_IMAGES(images) SET(LATEX_USE_INDEX 1) ADD_LATEX_DOCUMENT(MyDoc.tex . MyDoc.bib)