mi024

College project "Projet IAD" master 1
git clone https://esimon.eu/repos/mi024.git
Log | Files | Refs | README

UseLATEX.cmake (53099B)


      1 # File: UseLATEX.cmake
      2 # CMAKE commands to actually use the LaTeX compiler
      3 # Version: 1.9.5
      4 # Author: Kenneth Moreland <kmorel@sandia.gov>
      5 # Modified by: Étienne Simon
      6 #
      7 # Copyright 2004 Sandia Corporation.
      8 # Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
      9 # license for use of this work by or on behalf of the
     10 # U.S. Government. Redistribution and use in source and binary forms, with
     11 # or without modification, are permitted provided that this Notice and any
     12 # statement of authorship are reproduced on all copies.
     13 #
     14 # The following function is defined:
     15 #
     16 # ADD_LATEX_DOCUMENT(<tex_file>
     17 #                    [BIBFILES <bib_files>]
     18 #                    [INPUTS <input_tex_files>]
     19 #                    [IMAGE_DIRS] <image_directories>
     20 #                    [IMAGES] <image_files>
     21 #                    [CONFIGURE] <tex_files>
     22 #                    [DEPENDS] <tex_files>
     23 #                    [MULTIBIB_NEWCITES] <suffix_list>
     24 #                    [USE_INDEX] [USE_GLOSSARY] [USE_NOMENCL]
     25 #                    [DEFAULT_PDF] [DEFAULT_SAFEPDF]
     26 #                    [MANGLE_TARGET_NAMES])
     27 #       Adds targets that compile <tex_file>.  The latex output is placed
     28 #       in LATEX_OUTPUT_PATH or CMAKE_CURRENT_BINARY_DIR if the former is
     29 #       not set.  The latex program is picky about where files are located,
     30 #       so all input files are copied from the source directory to the
     31 #       output directory.  This includes the target tex file, any tex file
     32 #       listed with the INPUTS option, the bibliography files listed with
     33 #       the BIBFILES option, and any .cls, .bst, and .clo files found in
     34 #       the current source directory.  Images found in the IMAGE_DIRS
     35 #       directories or listed by IMAGES are also copied to the output
     36 #       directory and coverted to an appropriate format if necessary.  Any
     37 #       tex files also listed with the CONFIGURE option are also processed
     38 #       with the CMake CONFIGURE_FILE command (with the @ONLY flag).  Any
     39 #       file listed in CONFIGURE but not the target tex file or listed with
     40 #       INPUTS has no effect. DEPENDS can be used to specify generated files
     41 #       that are needed to compile the latex target.
     42 #
     43 #       The following targets are made:
     44 #               dvi: Makes <name>.dvi
     45 #               pdf: Makes <name>.pdf using pdflatex.
     46 #               safepdf: Makes <name>.pdf using ps2pdf.  If using the default
     47 #                       program arguments, this will ensure all fonts are
     48 #                       embedded and no lossy compression has been performed
     49 #                       on images.
     50 #               ps: Makes <name>.ps
     51 #               html: Makes <name>.html
     52 #               auxclean: Deletes <name>.aux and other auxiliary files.
     53 #                       This is sometimes necessary if a LaTeX error occurs
     54 #                       and writes a bad aux file.  Unlike the regular clean
     55 #                       target, it does not delete other input files, such as
     56 #                       converted images, to save time on the rebuild.
     57 #
     58 #       If the argument MANGLE_TARGET_NAMES is given, then each of the
     59 #       target names above will be mangled with the <tex_file> name.  This
     60 #       is to make the targets unique if ADD_LATEX_DOCUMENT is called for
     61 #       multiple documents.  If the argument USE_INDEX is given, then
     62 #       commands to build an index are made.  If the argument USE_GLOSSARY
     63 #       is given, then commands to build a glossary are made.  If the
     64 #       argument MULTIBIB_NEWCITES is given, then additional bibtex calls
     65 #       are added to the build to support the extra auxiliary files created
     66 #       with the \newcite command in the multibib package.
     67 #
     68 # History:
     69 #
     70 # local Add VERBATIM and removed ALL to ADD_CUSTOM_* commands.
     71 #
     72 # 1.9.5 Add support for image types not directly supported by either latex
     73 #       or pdflatex.  (Thanks to Jorge Gerardo Pena Pastor for SVG support.)
     74 #
     75 # 1.9.4 Fix issues with filenames containing multiple periods.
     76 #
     77 # 1.9.3 Hide some variables that are now cached but should not show up in
     78 #       the ccmake list of variables.
     79 #
     80 # 1.9.2 Changed MACRO declarations to FUNCTION declarations.  The better
     81 #       FUNCTION scoping will hopefully avoid some common but subtle bugs.
     82 #       This implicitly increases the minimum CMake version to 4.6 (although
     83 #       I honestly only test it with the latest 4.8 version).
     84 #
     85 #       Since we are updating the minimum CMake version, I'm going to start
     86 #       using the builtin LIST commands that are now available.
     87 #
     88 #       Favor using pdftops from the Poppler package to convert from pdf to
     89 #       eps.  It does a much better job than ImageMagick or ghostscript.
     90 #
     91 # 1.9.1 Fixed typo that caused the LATEX_SMALL_IMAGES option to fail to
     92 #       activate.
     93 #
     94 # 1.9.0 Add support for the multibib package (thanks to Antonio LaTorre).
     95 #
     96 # 1.8.2 Fix corner case when an argument name was also a variable containing
     97 #       the text of an argument.  In this case, the CMake IF was matching
     98 #       the argument text with the contents of the variable with the same
     99 #       argument name.
    100 #
    101 # 1.8.1 Fix problem where ps2pdf was not getting the appropriate arguments.
    102 #
    103 # 1.8.0 Add support for synctex.
    104 #
    105 # 1.7.7 Support calling xindy when making glossaries.
    106 #
    107 #       Improved make clean support.
    108 #
    109 # 1.7.6 Add support for the nomencl package (thanks to Myles English).
    110 #
    111 # 1.7.5 Fix issue with bibfiles being copied two different ways, which causes
    112 #       Problems with dependencies (thanks to Edwin van Leeuwen).
    113 #
    114 # 1.7.4 Added the DEFAULT_SAFEPDF option (thanks to Raymond Wan).
    115 #
    116 #       Added warnings when image directories are not found (and were
    117 #       probably not given relative to the source directory).
    118 #
    119 # 1.7.3 Fix some issues with interactions between makeglossaries and bibtex
    120 #       (thanks to Mark de Wever).
    121 #
    122 # 1.7.2 Use ps2pdf to convert eps to pdf to get around the problem with
    123 #       ImageMagick dropping the bounding box (thanks to Lukasz Lis).
    124 #
    125 # 1.7.1 Fixed some dependency issues.
    126 #
    127 # 1.7.0 Added DEPENDS options (thanks to Theodore Papadopoulo).
    128 #
    129 # 1.6.1 Ported the makeglossaries command to CMake and embedded the port
    130 #       into UseLATEX.cmake.
    131 #
    132 # 1.6.0 Allow the use of the makeglossaries command.  Thanks to Oystein
    133 #       S. Haaland for the patch.
    134 #
    135 # 1.5.0 Allow any type of file in the INPUTS lists, not just tex file
    136 #       (suggested by Eric Noulard).  As a consequence, the ability to
    137 #       specify tex files without the .tex extension is removed.  The removed
    138 #       function is of dubious value anyway.
    139 #
    140 #       When copying input files, skip over any file that exists in the
    141 #       binary directory but does not exist in the source directory with the
    142 #       assumption that these files were added by some other mechanism.  I
    143 #       find this useful when creating large documents with multiple
    144 #       chapters that I want to build separately (for speed) as I work on
    145 #       them.  I use the same boilerplate as the starting point for all
    146 #       and just copy it with different configurations.  This was what the
    147 #       separate ADD_LATEX_DOCUMENT method was supposed to originally be for.
    148 #       Since its external use is pretty much deprecated, I removed that
    149 #       documentation.
    150 #
    151 # 1.4.1 Copy .sty files along with the other class and package files.
    152 #
    153 # 1.4.0 Added a MANGLE_TARGET_NAMES option that will mangle the target names.
    154 #
    155 #       Fixed problem with copying bib files that became apparent with
    156 #       CMake 2.4.
    157 #
    158 # 1.3.0 Added a LATEX_OUTPUT_PATH variable that allows you or the user to
    159 #       specify where the built latex documents to go.  This is especially
    160 #       handy if you want to do in-source builds.
    161 #
    162 #       Removed the ADD_LATEX_IMAGES macro and absorbed the functionality
    163 #       into ADD_LATEX_DOCUMENT.  The old interface was always kind of
    164 #       clunky anyway since you had to specify the image directory in both
    165 #       places.  It also made supporting LATEX_OUTPUT_PATH problematic.
    166 #
    167 #       Added support for jpeg files.
    168 #
    169 # 1.2.0 Changed the configuration options yet again.  Removed the NO_CONFIGURE
    170 #       Replaced it with a CONFIGURE option that lists input files for which
    171 #       configure should be run.
    172 #
    173 #       The pdf target no longer depends on the dvi target.  This allows you
    174 #       to build latex documents that require pdflatex.  Also added an option
    175 #       to make the pdf target the default one.
    176 #
    177 # 1.1.1 Added the NO_CONFIGURE option.  The @ character can be used when
    178 #       specifying table column separators.  If two or more are used, then
    179 #       will incorrectly substitute them.
    180 #
    181 # 1.1.0 Added ability include multiple bib files.  Added ability to do copy
    182 #       sub-tex files for multipart tex files.
    183 #
    184 # 1.0.0 If both ps and pdf type images exist, just copy the one that
    185 #       matches the current render mode.  Replaced a bunch of STRING
    186 #       commands with GET_FILENAME_COMPONENT commands that were made to do
    187 #       the desired function.
    188 #
    189 # 0.4.0 First version posted to CMake Wiki.
    190 #
    191 
    192 #############################################################################
    193 # Find the location of myself while originally executing.  If you do this
    194 # inside of a macro, it will recode where the macro was invoked.
    195 #############################################################################
    196 SET(LATEX_USE_LATEX_LOCATION ${CMAKE_CURRENT_LIST_FILE}
    197   CACHE INTERNAL "Location of UseLATEX.cmake file." FORCE
    198   )
    199 
    200 #############################################################################
    201 # Generic helper functions
    202 #############################################################################
    203 
    204 FUNCTION(LATEX_LIST_CONTAINS var value)
    205   SET(input_list ${ARGN})
    206   LIST(FIND input_list "${value}" index)
    207   IF (index GREATER -1)
    208     SET(${var} TRUE PARENT_SCOPE)
    209   ELSE (index GREATER -1)
    210     SET(${var} PARENT_SCOPE)
    211   ENDIF (index GREATER -1)
    212 ENDFUNCTION(LATEX_LIST_CONTAINS)
    213 
    214 # Parse function arguments.  Variables containing the results are placed
    215 # in the global scope for historical reasons.
    216 FUNCTION(LATEX_PARSE_ARGUMENTS prefix arg_names option_names)
    217   SET(DEFAULT_ARGS)
    218   FOREACH(arg_name ${arg_names})
    219     SET(${prefix}_${arg_name} CACHE INTERNAL "${prefix} argument" FORCE)
    220   ENDFOREACH(arg_name)
    221   FOREACH(option ${option_names})
    222     SET(${prefix}_${option} CACHE INTERNAL "${prefix} option" FORCE)
    223   ENDFOREACH(option)
    224 
    225   SET(current_arg_name DEFAULT_ARGS)
    226   SET(current_arg_list)
    227   FOREACH(arg ${ARGN})
    228     LATEX_LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
    229     LATEX_LIST_CONTAINS(is_option ${arg} ${option_names})
    230     IF (is_arg_name)
    231       SET(${prefix}_${current_arg_name} ${current_arg_list}
    232         CACHE INTERNAL "${prefix} argument" FORCE)
    233       SET(current_arg_name ${arg})
    234       SET(current_arg_list)
    235     ELSEIF (is_option)
    236       SET(${prefix}_${arg} TRUE CACHE INTERNAL "${prefix} option" FORCE)
    237     ELSE (is_arg_name)
    238       SET(current_arg_list ${current_arg_list} ${arg})
    239     ENDIF (is_arg_name)
    240   ENDFOREACH(arg)
    241   SET(${prefix}_${current_arg_name} ${current_arg_list}
    242     CACHE INTERNAL "${prefix} argument" FORCE)
    243 ENDFUNCTION(LATEX_PARSE_ARGUMENTS)
    244 
    245 # Match the contents of a file to a regular expression.
    246 FUNCTION(LATEX_FILE_MATCH variable filename regexp default)
    247   # The FILE STRINGS command would be a bit better, but I'm not totally sure
    248   # the match will always be to a whole line, and I don't want to break things.
    249   FILE(READ ${filename} file_contents)
    250   STRING(REGEX MATCHALL "${regexp}"
    251     match_result ${file_contents}
    252     )
    253   IF (match_result)
    254     SET(${variable} "${match_result}" PARENT_SCOPE)
    255   ELSE (match_result)
    256     SET(${variable} "${default}" PARENT_SCOPE)
    257   ENDIF (match_result)
    258 ENDFUNCTION(LATEX_FILE_MATCH)
    259 
    260 # A version of GET_FILENAME_COMPONENT that treats extensions after the last
    261 # period rather than the first.  To the best of my knowledge, all filenames
    262 # typically used by LaTeX, including image files, have small extensions
    263 # after the last dot.
    264 FUNCTION(LATEX_GET_FILENAME_COMPONENT varname filename type)
    265   SET(result)
    266   IF ("${type}" STREQUAL "NAME_WE")
    267     GET_FILENAME_COMPONENT(name ${filename} NAME)
    268     STRING(REGEX REPLACE "\\.[^.]*\$" "" result "${name}")
    269   ELSEIF ("${type}" STREQUAL "EXT")
    270     GET_FILENAME_COMPONENT(name ${filename} NAME)
    271     STRING(REGEX MATCH "\\.[^.]*\$" result "${name}")
    272   ELSE ("${type}" STREQUAL "NAME_WE")
    273     GET_FILENAME_COMPONENT(result ${filename} ${type})
    274   ENDIF ("${type}" STREQUAL "NAME_WE")
    275   SET(${varname} "${result}" PARENT_SCOPE)
    276 ENDFUNCTION(LATEX_GET_FILENAME_COMPONENT)
    277 
    278 #############################################################################
    279 # Functions that perform processing during a LaTeX build.
    280 #############################################################################
    281 FUNCTION(LATEX_MAKEGLOSSARIES)
    282   # This is really a bare bones port of the makeglossaries perl script into
    283   # CMake scripting.
    284   MESSAGE("**************************** In makeglossaries")
    285   IF (NOT LATEX_TARGET)
    286     MESSAGE(SEND_ERROR "Need to define LATEX_TARGET")
    287   ENDIF (NOT LATEX_TARGET)
    288 
    289   SET(aux_file ${LATEX_TARGET}.aux)
    290 
    291   IF (NOT EXISTS ${aux_file})
    292     MESSAGE(SEND_ERROR "${aux_file} does not exist.  Run latex on your target file.")
    293   ENDIF (NOT EXISTS ${aux_file})
    294 
    295   LATEX_FILE_MATCH(newglossary_lines ${aux_file}
    296     "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
    297     "@newglossary{main}{glg}{gls}{glo}"
    298     )
    299 
    300   LATEX_FILE_MATCH(istfile_line ${aux_file}
    301     "@istfilename[ \t]*{([^}]*)}"
    302     "@istfilename{${LATEX_TARGET}.ist}"
    303     )
    304   STRING(REGEX REPLACE "@istfilename[ \t]*{([^}]*)}" "\\1"
    305     istfile ${istfile_line}
    306     )
    307 
    308   STRING(REGEX MATCH ".*\\.xdy" use_xindy "${istfile}")
    309   IF (use_xindy)
    310     MESSAGE("*************** Using xindy")
    311     IF (NOT XINDY_COMPILER)
    312       MESSAGE(SEND_ERROR "Need to define XINDY_COMPILER")
    313     ENDIF (NOT XINDY_COMPILER)
    314   ELSE (use_xindy)
    315     MESSAGE("*************** Using makeindex")
    316     IF (NOT MAKEINDEX_COMPILER)
    317       MESSAGE(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
    318     ENDIF (NOT MAKEINDEX_COMPILER)
    319   ENDIF (use_xindy)
    320 
    321   FOREACH(newglossary ${newglossary_lines})
    322     STRING(REGEX REPLACE
    323       "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
    324       "\\1" glossary_name ${newglossary}
    325       )
    326     STRING(REGEX REPLACE
    327       "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
    328       "${LATEX_TARGET}.\\2" glossary_log ${newglossary}
    329       )
    330     STRING(REGEX REPLACE
    331       "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
    332       "${LATEX_TARGET}.\\3" glossary_out ${newglossary}
    333       )
    334     STRING(REGEX REPLACE
    335       "@newglossary[ \t]*{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}"
    336       "${LATEX_TARGET}.\\4" glossary_in ${newglossary}
    337       )
    338 
    339     IF (use_xindy)
    340       LATEX_FILE_MATCH(xdylanguage_line ${aux_file}
    341         "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
    342         "@xdylanguage{${glossary_name}}{english}"
    343         )
    344       STRING(REGEX REPLACE
    345         "@xdylanguage[ \t]*{${glossary_name}}{([^}]*)}"
    346         "\\1"
    347         language
    348         ${xdylanguage_line}
    349         )
    350       # What crazy person makes a LaTeX index generater that uses different
    351       # identifiers for language than babel (or at least does not support
    352       # the old ones)?
    353       IF (${language} STREQUAL "frenchb")
    354         SET(language "french")
    355       ELSEIF (${language} MATCHES "^n?germanb?$")
    356         SET(language "german")
    357       ELSEIF (${language} STREQUAL "magyar")
    358         SET(language "hungarian")
    359       ELSEIF (${language} STREQUAL "lsorbian")
    360         SET(language "lower-sorbian")
    361       ELSEIF (${language} STREQUAL "norsk")
    362         SET(language "norwegian")
    363       ELSEIF (${language} STREQUAL "portuges")
    364         SET(language "portuguese")
    365       ELSEIF (${language} STREQUAL "russianb")
    366         SET(language "russian")
    367       ELSEIF (${language} STREQUAL "slovene")
    368         SET(language "slovenian")
    369       ELSEIF (${language} STREQUAL "ukraineb")
    370         SET(language "ukrainian")
    371       ELSEIF (${language} STREQUAL "usorbian")
    372         SET(language "upper-sorbian")
    373       ENDIF (${language} STREQUAL "frenchb")
    374       IF (language)
    375         SET(language_flags "-L ${language}")
    376       ELSE (language)
    377         SET(language_flags "")
    378       ENDIF (language)
    379 
    380       LATEX_FILE_MATCH(codepage_line ${aux_file}
    381         "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
    382         "@gls@codepage{${glossary_name}}{utf}"
    383         )
    384       STRING(REGEX REPLACE
    385         "@gls@codepage[ \t]*{${glossary_name}}{([^}]*)}"
    386         "\\1"
    387         codepage
    388         ${codepage_line}
    389         )
    390       IF (codepage)
    391         SET(codepage_flags "-C ${codepage}")
    392       ELSE (codepage)
    393         # Ideally, we would check that the language is compatible with the
    394         # default codepage, but I'm hoping that distributions will be smart
    395         # enough to specify their own codepage.  I know, it's asking a lot.
    396         SET(codepage_flags "")
    397       ENDIF (codepage)
    398 
    399       MESSAGE("${XINDY_COMPILER} ${MAKEGLOSSARIES_COMPILER_FLAGS} ${language_flags} ${codepage_flags} -I xindy -M ${glossary_name} -t ${glossary_log} -o ${glossary_out} ${glossary_in}"
    400         )
    401       EXEC_PROGRAM(${XINDY_COMPILER}
    402         ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
    403           ${language_flags}
    404           ${codepage_flags}
    405           -I xindy
    406           -M ${glossary_name}
    407           -t ${glossary_log}
    408           -o ${glossary_out}
    409           ${glossary_in}
    410         OUTPUT_VARIABLE xindy_output
    411         )
    412       MESSAGE("${xindy_output}")
    413 
    414       # So, it is possible (perhaps common?) for aux files to specify a
    415       # language and codepage that are incompatible with each other.  Check
    416       # for that condition, and if it happens run again with the default
    417       # codepage.
    418       IF ("${xindy_output}" MATCHES "^Cannot locate xindy module for language (.+) in codepage (.+)\\.$")
    419         MESSAGE("*************** Retrying xindy with default codepage.")
    420         EXEC_PROGRAM(${XINDY_COMPILER}
    421           ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
    422             ${language_flags}
    423             -I xindy
    424             -M ${glossary_name}
    425             -t ${glossary_log}
    426             -o ${glossary_out}
    427             ${glossary_in}
    428           )
    429       ENDIF ("${xindy_output}" MATCHES "^Cannot locate xindy module for language (.+) in codepage (.+)\\.$")
    430       #ENDIF ("${xindy_output}" MATCHES "Cannot locate xindy module for language (.+) in codepage (.+)\\.")
    431       
    432     ELSE (use_xindy)
    433       MESSAGE("${MAKEINDEX_COMPILER} ${MAKEGLOSSARIES_COMPILER_FLAGS} -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}")
    434       EXEC_PROGRAM(${MAKEINDEX_COMPILER} ARGS ${MAKEGLOSSARIES_COMPILER_FLAGS}
    435         -s ${istfile} -t ${glossary_log} -o ${glossary_out} ${glossary_in}
    436         )
    437     ENDIF (use_xindy)
    438 
    439   ENDFOREACH(newglossary)
    440 ENDFUNCTION(LATEX_MAKEGLOSSARIES)
    441 
    442 FUNCTION(LATEX_MAKENOMENCLATURE)
    443   MESSAGE("**************************** In makenomenclature")
    444   IF (NOT LATEX_TARGET)
    445     MESSAGE(SEND_ERROR "Need to define LATEX_TARGET")
    446   ENDIF (NOT LATEX_TARGET)
    447 
    448   IF (NOT MAKEINDEX_COMPILER)
    449     MESSAGE(SEND_ERROR "Need to define MAKEINDEX_COMPILER")
    450   ENDIF (NOT MAKEINDEX_COMPILER)
    451 
    452   SET(nomencl_out ${LATEX_TARGET}.nls)
    453   SET(nomencl_in ${LATEX_TARGET}.nlo)
    454 
    455   EXEC_PROGRAM(${MAKEINDEX_COMPILER} ARGS ${MAKENOMENCLATURE_COMPILER_FLAGS}
    456     ${nomencl_in} -s "nomencl.ist" -o ${nomencl_out}
    457     )
    458 ENDFUNCTION(LATEX_MAKENOMENCLATURE)
    459 
    460 FUNCTION(LATEX_CORRECT_SYNCTEX)
    461   MESSAGE("**************************** In correct SyncTeX")
    462   IF (NOT LATEX_TARGET)
    463     MESSAGE(SEND_ERROR "Need to define LATEX_TARGET")
    464   ENDIF (NOT LATEX_TARGET)
    465 
    466   IF (NOT GZIP)
    467     MESSAGE(SEND_ERROR "Need to define GZIP")
    468   ENDIF (NOT GZIP)
    469 
    470   IF (NOT LATEX_SOURCE_DIRECTORY)
    471     MESSAGE(SEND_ERROR "Need to define LATEX_SOURCE_DIRECTORY")
    472   ENDIF (NOT LATEX_SOURCE_DIRECTORY)
    473 
    474   IF (NOT LATEX_BINARY_DIRECTORY)
    475     MESSAGE(SEND_ERROR "Need to define LATEX_BINARY_DIRECTORY")
    476   ENDIF (NOT LATEX_BINARY_DIRECTORY)
    477 
    478   SET(synctex_file ${LATEX_BINARY_DIRECTORY}/${LATEX_TARGET}.synctex)
    479   SET(synctex_file_gz ${synctex_file}.gz)
    480 
    481   IF (EXISTS ${synctex_file_gz})
    482 
    483     MESSAGE("Making backup of synctex file.")
    484     CONFIGURE_FILE(${synctex_file_gz} ${synctex_file}.bak.gz COPYONLY)
    485 
    486     MESSAGE("Uncompressing synctex file.")
    487     EXEC_PROGRAM(${GZIP}
    488       ARGS --decompress ${synctex_file_gz}
    489       )
    490 
    491     MESSAGE("Reading synctex file.")
    492     FILE(READ ${synctex_file} synctex_data)
    493 
    494     MESSAGE("Replacing relative with absolute paths.")
    495     STRING(REGEX REPLACE
    496       "(Input:[0-9]+:)([^/\n][^\n]*)"
    497       "\\1${LATEX_SOURCE_DIRECTORY}/\\2"
    498       synctex_data
    499       "${synctex_data}"
    500       )
    501 
    502     MESSAGE("Writing synctex file.")
    503     FILE(WRITE ${synctex_file} "${synctex_data}")
    504 
    505     MESSAGE("Compressing synctex file.")
    506     EXEC_PROGRAM(${GZIP}
    507       ARGS ${synctex_file}
    508       )
    509 
    510   ELSE (EXISTS ${synctex_file_gz})
    511 
    512     MESSAGE(SEND_ERROR "File ${synctex_file_gz} not found.  Perhaps synctex is not supported by your LaTeX compiler.")
    513 
    514   ENDIF (EXISTS ${synctex_file_gz})
    515 
    516 ENDFUNCTION(LATEX_CORRECT_SYNCTEX)
    517 
    518 #############################################################################
    519 # Helper functions for establishing LaTeX build.
    520 #############################################################################
    521 
    522 FUNCTION(LATEX_NEEDIT VAR NAME)
    523   IF (NOT ${VAR})
    524     MESSAGE(SEND_ERROR "I need the ${NAME} command.")
    525   ENDIF(NOT ${VAR})
    526 ENDFUNCTION(LATEX_NEEDIT)
    527 
    528 FUNCTION(LATEX_WANTIT VAR NAME)
    529   IF (NOT ${VAR})
    530     MESSAGE(STATUS "I could not find the ${NAME} command.")
    531   ENDIF(NOT ${VAR})
    532 ENDFUNCTION(LATEX_WANTIT)
    533 
    534 FUNCTION(LATEX_SETUP_VARIABLES)
    535   SET(LATEX_OUTPUT_PATH "${LATEX_OUTPUT_PATH}"
    536     CACHE PATH "If non empty, specifies the location to place LaTeX output."
    537     )
    538 
    539   FIND_PACKAGE(LATEX)
    540 
    541   FIND_PROGRAM(XINDY_COMPILER
    542     NAME xindy
    543     PATHS ${MIKTEX_BINARY_PATH} /usr/bin
    544     )
    545 
    546   FIND_PACKAGE(UnixCommands)
    547 
    548   FIND_PROGRAM(PDFTOPS_CONVERTER
    549     NAMES pdftops
    550     DOC "The pdf to ps converter program from the Poppler package."
    551     )
    552 
    553   MARK_AS_ADVANCED(CLEAR
    554     LATEX_COMPILER
    555     PDFLATEX_COMPILER
    556     BIBTEX_COMPILER
    557     MAKEINDEX_COMPILER
    558     XINDY_COMPILER
    559     DVIPS_CONVERTER
    560     PS2PDF_CONVERTER
    561     PDFTOPS_CONVERTER
    562     LATEX2HTML_CONVERTER
    563     )
    564 
    565   LATEX_NEEDIT(LATEX_COMPILER latex)
    566   LATEX_WANTIT(PDFLATEX_COMPILER pdflatex)
    567   LATEX_NEEDIT(BIBTEX_COMPILER bibtex)
    568   LATEX_NEEDIT(MAKEINDEX_COMPILER makeindex)
    569   LATEX_WANTIT(DVIPS_CONVERTER dvips)
    570   LATEX_WANTIT(PS2PDF_CONVERTER ps2pdf)
    571   LATEX_WANTIT(PDFTOPS_CONVERTER pdftops)
    572   LATEX_WANTIT(LATEX2HTML_CONVERTER latex2html)
    573 
    574   SET(LATEX_COMPILER_FLAGS "-interaction=nonstopmode"
    575     CACHE STRING "Flags passed to latex.")
    576   SET(PDFLATEX_COMPILER_FLAGS ${LATEX_COMPILER_FLAGS}
    577     CACHE STRING "Flags passed to pdflatex.")
    578   SET(LATEX_SYNCTEX_FLAGS "-synctex=1"
    579     CACHE STRING "latex/pdflatex flags used to create synctex file.")
    580   SET(BIBTEX_COMPILER_FLAGS ""
    581     CACHE STRING "Flags passed to bibtex.")
    582   SET(MAKEINDEX_COMPILER_FLAGS ""
    583     CACHE STRING "Flags passed to makeindex.")
    584   SET(MAKEGLOSSARIES_COMPILER_FLAGS ""
    585     CACHE STRING "Flags passed to makeglossaries.")
    586   SET(MAKENOMENCLATURE_COMPILER_FLAGS ""
    587     CACHE STRING "Flags passed to makenomenclature.")
    588   SET(DVIPS_CONVERTER_FLAGS "-Ppdf -G0 -t letter"
    589     CACHE STRING "Flags passed to dvips.")
    590   SET(PS2PDF_CONVERTER_FLAGS "-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dMonoImageFilter=/FlateEncode"
    591     CACHE STRING "Flags passed to ps2pdf.")
    592   SET(PDFTOPS_CONVERTER_FLAGS -r 600
    593     CACHE STRING "Flags passed to pdftops.")
    594   SET(LATEX2HTML_CONVERTER_FLAGS ""
    595     CACHE STRING "Flags passed to latex2html.")
    596   MARK_AS_ADVANCED(
    597     LATEX_COMPILER_FLAGS
    598     PDFLATEX_COMPILER_FLAGS
    599     LATEX_SYNCTEX_FLAGS
    600     BIBTEX_COMPILER_FLAGS
    601     MAKEINDEX_COMPILER_FLAGS
    602     MAKEGLOSSARIES_COMPILER_FLAGS
    603     MAKENOMENCLATURE_COMPILER_FLAGS
    604     DVIPS_CONVERTER_FLAGS
    605     PS2PDF_CONVERTER_FLAGS
    606     PDFTOPS_CONVERTER_FLAGS
    607     LATEX2HTML_CONVERTER_FLAGS
    608     )
    609   SEPARATE_ARGUMENTS(LATEX_COMPILER_FLAGS)
    610   SEPARATE_ARGUMENTS(PDFLATEX_COMPILER_FLAGS)
    611   SEPARATE_ARGUMENTS(LATEX_SYNCTEX_FLAGS)
    612   SEPARATE_ARGUMENTS(BIBTEX_COMPILER_FLAGS)
    613   SEPARATE_ARGUMENTS(MAKEINDEX_COMPILER_FLAGS)
    614   SEPARATE_ARGUMENTS(MAKEGLOSSARIES_COMPILER_FLAGS)
    615   SEPARATE_ARGUMENTS(MAKENOMENCLATURE_COMPILER_FLAGS)
    616   SEPARATE_ARGUMENTS(DVIPS_CONVERTER_FLAGS)
    617   SEPARATE_ARGUMENTS(PS2PDF_CONVERTER_FLAGS)
    618   SEPARATE_ARGUMENTS(PDFTOPS_CONVERTER_FLAGS)
    619   SEPARATE_ARGUMENTS(LATEX2HTML_CONVERTER_FLAGS)
    620 
    621   FIND_PROGRAM(IMAGEMAGICK_CONVERT convert
    622     DOC "The convert program that comes with ImageMagick (available at http://www.imagemagick.org)."
    623     )
    624   IF (NOT IMAGEMAGICK_CONVERT)
    625     MESSAGE(SEND_ERROR "Could not find convert program.  Please download ImageMagick from http://www.imagemagick.org and install.")
    626   ENDIF (NOT IMAGEMAGICK_CONVERT)
    627 
    628   OPTION(LATEX_USE_SYNCTEX
    629     "If on, have LaTeX generate a synctex file, which WYSIWYG editors can use to correlate output files like dvi and pdf with the lines of LaTeX source that generates them.  In addition to adding the LATEX_SYNCTEX_FLAGS to the command line, this option also adds build commands that \"corrects\" the resulting synctex file to point to the original LaTeX files rather than those generated by UseLATEX.cmake."
    630     OFF
    631     )
    632 
    633   OPTION(LATEX_SMALL_IMAGES
    634     "If on, the raster images will be converted to 1/6 the original size.  This is because papers usually require 600 dpi images whereas most monitors only require at most 96 dpi.  Thus, smaller images make smaller files for web distributation and can make it faster to read dvi files."
    635     OFF)
    636   IF (LATEX_SMALL_IMAGES)
    637     SET(LATEX_RASTER_SCALE 16)
    638     SET(LATEX_OPPOSITE_RASTER_SCALE 100)
    639   ELSE (LATEX_SMALL_IMAGES)
    640     SET(LATEX_RASTER_SCALE 100)
    641     SET(LATEX_OPPOSITE_RASTER_SCALE 16)
    642   ENDIF (LATEX_SMALL_IMAGES)
    643 
    644   # Just holds extensions for known image types.  They should all be lower case.
    645   # For historical reasons, these are all declared in the global scope.
    646   SET(LATEX_DVI_VECTOR_IMAGE_EXTENSIONS .eps CACHE INTERNAL "")
    647   SET(LATEX_DVI_RASTER_IMAGE_EXTENSIONS CACHE INTERNAL "")
    648   SET(LATEX_DVI_IMAGE_EXTENSIONS
    649     ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS}
    650     ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
    651     CACHE INTERNAL ""
    652     )
    653 
    654   SET(LATEX_PDF_VECTOR_IMAGE_EXTENSIONS .pdf CACHE INTERNAL "")
    655   SET(LATEX_PDF_RASTER_IMAGE_EXTENSIONS .png .jpeg .jpg CACHE INTERNAL "")
    656   SET(LATEX_PDF_IMAGE_EXTENSIONS
    657     ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS}
    658     ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS}
    659     CACHE INTERNAL ""
    660     )
    661 
    662   SET(LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS .svg CACHE INTERNAL "")
    663   SET(LATEX_OTHER_RASTER_IMAGE_EXTENSIONS .tif .tiff .gif CACHE INTERNAL "")
    664   SET(LATEX_OTHER_IMAGE_EXTENSIONS
    665     ${LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS}
    666     ${LATEX_OTHER_RASTER_IMAGE_EXTENSIONS}
    667     CACHE INTERNAL ""
    668     )
    669 
    670   SET(LATEX_VECTOR_IMAGE_EXTENSIONS
    671     ${LATEX_DVI_VECTOR_IMAGE_EXTENSIONS}
    672     ${LATEX_PDF_VECTOR_IMAGE_EXTENSIONS}
    673     ${LATEX_OTHER_VECTOR_IMAGE_EXTENSIONS}
    674     CACHE INTERNAL ""
    675     )
    676   SET(LATEX_RASTER_IMAGE_EXTENSIONS
    677     ${LATEX_DVI_RASTER_IMAGE_EXTENSIONS}
    678     ${LATEX_PDF_RASTER_IMAGE_EXTENSIONS}
    679     ${LATEX_OTHER_RASTER_IMAGE_EXTENSIONS}
    680     CACHE INTERNAL ""
    681     )
    682   SET(LATEX_IMAGE_EXTENSIONS
    683     ${LATEX_DVI_IMAGE_EXTENSIONS}
    684     ${LATEX_PDF_IMAGE_EXTENSIONS}
    685     ${LATEX_OTHER_IMAGE_EXTENSIONS}
    686     CACHE INTERNAL ""
    687     )
    688 ENDFUNCTION(LATEX_SETUP_VARIABLES)
    689 
    690 FUNCTION(LATEX_GET_OUTPUT_PATH var)
    691   SET(latex_output_path)
    692   IF (LATEX_OUTPUT_PATH)
    693     IF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    694       MESSAGE(SEND_ERROR "You cannot set LATEX_OUTPUT_PATH to the same directory that contains LaTeX input files.")
    695     ELSE ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    696       SET(latex_output_path "${LATEX_OUTPUT_PATH}")
    697     ENDIF ("${LATEX_OUTPUT_PATH}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    698   ELSE (LATEX_OUTPUT_PATH)
    699     IF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    700       MESSAGE(SEND_ERROR "LaTeX files must be built out of source or you must set LATEX_OUTPUT_PATH.")
    701     ELSE ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    702       SET(latex_output_path "${CMAKE_CURRENT_BINARY_DIR}")
    703     ENDIF ("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    704   ENDIF (LATEX_OUTPUT_PATH)
    705   SET(${var} ${latex_output_path} PARENT_SCOPE)
    706 ENDFUNCTION(LATEX_GET_OUTPUT_PATH)
    707 
    708 FUNCTION(LATEX_ADD_CONVERT_COMMAND
    709     output_path
    710     input_path
    711     output_extension
    712     input_extension
    713     flags
    714     )
    715   SET (converter ${IMAGEMAGICK_CONVERT})
    716   SET (convert_flags "")
    717   IF (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
    718     # ImageMagick has broken eps to pdf conversion
    719     # use ps2pdf instead
    720     IF (PS2PDF_CONVERTER)
    721       SET (converter ${PS2PDF_CONVERTER})
    722       SET (convert_flags -dEPSCrop ${PS2PDF_CONVERTER_FLAGS})
    723     ELSE (PS2PDF_CONVERTER)
    724       MESSAGE(SEND_ERROR "Using postscript files with pdflatex requires ps2pdf for conversion.")
    725     ENDIF (PS2PDF_CONVERTER)
    726   ELSEIF (${input_extension} STREQUAL ".pdf" AND ${output_extension} STREQUAL ".eps")
    727     # ImageMagick can also be sketchy on pdf to eps conversion.  Not good with
    728     # color spaces and tends to unnecessarily rasterize.
    729     # use pdftops instead
    730     IF (PDFTOPS_CONVERTER)
    731       SET(converter ${PDFTOPS_CONVERTER})
    732       SET(convert_flags -eps ${PDFTOPS_CONVERTER_FLAGS})
    733     ELSE (PDFTOPS_CONVERTER)
    734       MESSAGE(STATUS "Consider getting pdftops from Poppler to convert PDF images to EPS images.")
    735       SET (convert_flags ${flags})
    736     ENDIF (PDFTOPS_CONVERTER)
    737   ELSE (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
    738     SET (convert_flags ${flags})
    739   ENDIF (${input_extension} STREQUAL ".eps" AND ${output_extension} STREQUAL ".pdf")
    740 
    741   ADD_CUSTOM_COMMAND(OUTPUT ${output_path}
    742     COMMAND ${converter}
    743       ARGS ${convert_flags} ${input_path} ${output_path}
    744     DEPENDS ${input_path}
    745     VERBATIM
    746     )
    747 ENDFUNCTION(LATEX_ADD_CONVERT_COMMAND)
    748 
    749 # Makes custom commands to convert a file to a particular type.
    750 FUNCTION(LATEX_CONVERT_IMAGE
    751     output_files_var
    752     input_file
    753     output_extension
    754     convert_flags
    755     output_extensions
    756     other_files
    757     )
    758   SET(output_file_list)
    759   SET(input_dir ${CMAKE_CURRENT_SOURCE_DIR})
    760   LATEX_GET_OUTPUT_PATH(output_dir)
    761 
    762   LATEX_GET_FILENAME_COMPONENT(extension "${input_file}" EXT)
    763 
    764   # Check input filename for potential problems with LaTeX.
    765   LATEX_GET_FILENAME_COMPONENT(name "${input_file}" NAME_WE)
    766   IF (name MATCHES ".*\\..*")
    767     STRING(REPLACE "." "-" suggested_name "${name}")
    768     SET(suggested_name "${suggested_name}${extension}")
    769     MESSAGE(WARNING "Some LaTeX distributions have problems with image file names with multiple extensions.  Consider changing ${name}${extension} to something like ${suggested_name}.")
    770   ENDIF (name MATCHES ".*\\..*")
    771 
    772   STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} output_file
    773     "${input_file}")
    774 
    775   LATEX_LIST_CONTAINS(is_type ${extension} ${output_extensions})
    776   IF (is_type)
    777     IF (convert_flags)
    778       LATEX_ADD_CONVERT_COMMAND(${output_dir}/${output_file}
    779         ${input_dir}/${input_file} ${output_extension} ${extension}
    780         "${convert_flags}")
    781       SET(output_file_list ${output_file_list} ${output_dir}/${output_file})
    782     ELSE (convert_flags)
    783       # As a shortcut, we can just copy the file.
    784       ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${input_file}
    785         COMMAND ${CMAKE_COMMAND}
    786         ARGS -E copy ${input_dir}/${input_file} ${output_dir}/${input_file}
    787         DEPENDS ${input_dir}/${input_file}
    788         VERBATIM
    789         )
    790       SET(output_file_list ${output_file_list} ${output_dir}/${input_file})
    791     ENDIF (convert_flags)
    792   ELSE (is_type)
    793     SET(do_convert TRUE)
    794     # Check to see if there is another input file of the appropriate type.
    795     FOREACH(valid_extension ${output_extensions})
    796       STRING(REGEX REPLACE "\\.[^.]*\$" ${output_extension} try_file
    797         "${input_file}")
    798       LATEX_LIST_CONTAINS(has_native_file "${try_file}" ${other_files})
    799       IF (has_native_file)
    800         SET(do_convert FALSE)
    801       ENDIF (has_native_file)
    802     ENDFOREACH(valid_extension)
    803 
    804     # If we still need to convert, do it.
    805     IF (do_convert)
    806       LATEX_ADD_CONVERT_COMMAND(${output_dir}/${output_file}
    807         ${input_dir}/${input_file} ${output_extension} ${extension}
    808         "${convert_flags}")
    809       SET(output_file_list ${output_file_list} ${output_dir}/${output_file})
    810     ENDIF (do_convert)
    811   ENDIF (is_type)
    812 
    813   SET(${output_files_var} ${output_file_list} PARENT_SCOPE)
    814 ENDFUNCTION(LATEX_CONVERT_IMAGE)
    815 
    816 # Adds custom commands to process the given files for dvi and pdf builds.
    817 # Adds the output files to the given variables (does not replace).
    818 FUNCTION(LATEX_PROCESS_IMAGES dvi_outputs_var pdf_outputs_var)
    819   LATEX_GET_OUTPUT_PATH(output_dir)
    820   SET(dvi_outputs)
    821   SET(pdf_outputs)
    822   FOREACH(file ${ARGN})
    823     IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
    824       LATEX_GET_FILENAME_COMPONENT(extension "${file}" EXT)
    825       SET(convert_flags)
    826 
    827       # Check to see if we need to downsample the image.
    828       LATEX_LIST_CONTAINS(is_raster "${extension}"
    829         ${LATEX_RASTER_IMAGE_EXTENSIONS})
    830       IF (LATEX_SMALL_IMAGES)
    831         IF (is_raster)
    832           SET(convert_flags -resize ${LATEX_RASTER_SCALE}%)
    833         ENDIF (is_raster)
    834       ENDIF (LATEX_SMALL_IMAGES)
    835 
    836       # Make sure the output directory exists.
    837       LATEX_GET_FILENAME_COMPONENT(path "${output_dir}/${file}" PATH)
    838       MAKE_DIRECTORY("${path}")
    839 
    840       # Do conversions for dvi.
    841       LATEX_CONVERT_IMAGE(output_files "${file}" .eps "${convert_flags}"
    842         "${LATEX_DVI_IMAGE_EXTENSIONS}" "${ARGN}")
    843       SET(dvi_outputs ${dvi_outputs} ${output_files})
    844 
    845       # Do conversions for pdf.
    846       IF (is_raster)
    847         LATEX_CONVERT_IMAGE(output_files "${file}" .png "${convert_flags}"
    848           "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
    849         SET(pdf_outputs ${pdf_outputs} ${output_files})
    850       ELSE (is_raster)
    851         LATEX_CONVERT_IMAGE(output_files "${file}" .pdf "${convert_flags}"
    852           "${LATEX_PDF_IMAGE_EXTENSIONS}" "${ARGN}")
    853         SET(pdf_outputs ${pdf_outputs} ${output_files})
    854       ENDIF (is_raster)
    855     ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
    856       MESSAGE(WARNING "Could not find file ${CMAKE_CURRENT_SOURCE_DIR}/${file}.  Are you sure you gave relative paths to IMAGES?")
    857     ENDIF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
    858   ENDFOREACH(file)
    859 
    860   SET(${dvi_outputs_var} ${dvi_outputs} PARENT_SCOPE)
    861   SET(${pdf_outputs_var} ${pdf_outputs} PARENT_SCOPE)
    862 ENDFUNCTION(LATEX_PROCESS_IMAGES)
    863 
    864 FUNCTION(ADD_LATEX_IMAGES)
    865   MESSAGE(SEND_ERROR "The ADD_LATEX_IMAGES function is deprecated.  Image directories are specified with LATEX_ADD_DOCUMENT.")
    866 ENDFUNCTION(ADD_LATEX_IMAGES)
    867 
    868 FUNCTION(LATEX_COPY_GLOBBED_FILES pattern dest)
    869   FILE(GLOB file_list ${pattern})
    870   FOREACH(in_file ${file_list})
    871     LATEX_GET_FILENAME_COMPONENT(out_file ${in_file} NAME)
    872     CONFIGURE_FILE(${in_file} ${dest}/${out_file} COPYONLY)
    873   ENDFOREACH(in_file)
    874 ENDFUNCTION(LATEX_COPY_GLOBBED_FILES)
    875 
    876 FUNCTION(LATEX_COPY_INPUT_FILE file)
    877   LATEX_GET_OUTPUT_PATH(output_dir)
    878 
    879   IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
    880     LATEX_GET_FILENAME_COMPONENT(path ${file} PATH)
    881     FILE(MAKE_DIRECTORY ${output_dir}/${path})
    882 
    883     LATEX_LIST_CONTAINS(use_config ${file} ${LATEX_CONFIGURE})
    884     IF (use_config)
    885       CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${file}
    886         ${output_dir}/${file}
    887         @ONLY
    888         )
    889       ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file}
    890         COMMAND ${CMAKE_COMMAND}
    891         ARGS ${CMAKE_BINARY_DIR}
    892         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
    893         VERBATIM
    894         )
    895     ELSE (use_config)
    896       ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${file}
    897         COMMAND ${CMAKE_COMMAND}
    898         ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${output_dir}/${file}
    899         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
    900         VERBATIM
    901         )
    902     ENDIF (use_config)
    903   ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
    904     IF (EXISTS ${output_dir}/${file})
    905       # Special case: output exists but input does not.  Assume that it was
    906       # created elsewhere and skip the input file copy.
    907     ELSE (EXISTS ${output_dir}/${file})
    908       MESSAGE("Could not find input file ${CMAKE_CURRENT_SOURCE_DIR}/${file}")
    909     ENDIF (EXISTS ${output_dir}/${file})
    910   ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file})
    911 ENDFUNCTION(LATEX_COPY_INPUT_FILE)
    912 
    913 #############################################################################
    914 # Commands provided by the UseLATEX.cmake "package"
    915 #############################################################################
    916 
    917 FUNCTION(LATEX_USAGE command message)
    918   MESSAGE(SEND_ERROR
    919     "${message}\nUsage: ${command}(<tex_file>\n           [BIBFILES <bib_file> <bib_file> ...]\n           [INPUTS <tex_file> <tex_file> ...]\n           [IMAGE_DIRS <directory1> <directory2> ...]\n           [IMAGES <image_file1> <image_file2>\n           [CONFIGURE <tex_file> <tex_file> ...]\n           [DEPENDS <tex_file> <tex_file> ...]\n           [MULTIBIB_NEWCITES] <suffix_list>\n           [USE_INDEX] [USE_GLOSSARY] [USE_NOMENCL]\n           [DEFAULT_PDF] [DEFAULT_SAFEPDF]\n           [MANGLE_TARGET_NAMES])"
    920     )
    921 ENDFUNCTION(LATEX_USAGE command message)
    922 
    923 # Parses arguments to ADD_LATEX_DOCUMENT and ADD_LATEX_TARGETS and sets the
    924 # variables LATEX_TARGET, LATEX_IMAGE_DIR, LATEX_BIBFILES, LATEX_DEPENDS, and
    925 # LATEX_INPUTS.
    926 FUNCTION(PARSE_ADD_LATEX_ARGUMENTS command)
    927   LATEX_PARSE_ARGUMENTS(
    928     LATEX
    929     "BIBFILES;MULTIBIB_NEWCITES;INPUTS;IMAGE_DIRS;IMAGES;CONFIGURE;DEPENDS"
    930     "USE_INDEX;USE_GLOSSARY;USE_GLOSSARIES;USE_NOMENCL;DEFAULT_PDF;DEFAULT_SAFEPDF;MANGLE_TARGET_NAMES"
    931     ${ARGN}
    932     )
    933 
    934   # The first argument is the target latex file.
    935   IF (LATEX_DEFAULT_ARGS)
    936     LIST(GET LATEX_DEFAULT_ARGS 0 latex_main_input)
    937     LIST(REMOVE_AT LATEX_DEFAULT_ARGS 0)
    938     LATEX_GET_FILENAME_COMPONENT(latex_target ${latex_main_input} NAME_WE)
    939     SET(LATEX_MAIN_INPUT ${latex_main_input} CACHE INTERNAL "" FORCE)
    940     SET(LATEX_TARGET ${latex_target} CACHE INTERNAL "" FORCE)
    941   ELSE (LATEX_DEFAULT_ARGS)
    942     LATEX_USAGE(${command} "No tex file target given to ${command}.")
    943   ENDIF (LATEX_DEFAULT_ARGS)
    944 
    945   IF (LATEX_DEFAULT_ARGS)
    946     LATEX_USAGE(${command} "Invalid or depricated arguments: ${LATEX_DEFAULT_ARGS}")
    947   ENDIF (LATEX_DEFAULT_ARGS)
    948 
    949   # Backward compatibility between 1.6.0 and 1.6.1.
    950   IF (LATEX_USE_GLOSSARIES)
    951     SET(LATEX_USE_GLOSSARY TRUE CACHE INTERNAL "" FORCE)
    952   ENDIF (LATEX_USE_GLOSSARIES)
    953 ENDFUNCTION(PARSE_ADD_LATEX_ARGUMENTS)
    954 
    955 FUNCTION(ADD_LATEX_TARGETS_INTERNAL)
    956   IF (LATEX_USE_SYNCTEX)
    957     SET(synctex_flags ${LATEX_SYNCTEX_FLAGS})
    958   ELSE (LATEX_USE_SYNCTEX)
    959     SET(synctex_flags)
    960   ENDIF (LATEX_USE_SYNCTEX)
    961 
    962   # The commands to run LaTeX.  They are repeated multiple times.
    963   SET(latex_build_command
    964     ${LATEX_COMPILER} ${LATEX_COMPILER_FLAGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
    965     )
    966   SET(pdflatex_build_command
    967     ${PDFLATEX_COMPILER} ${PDFLATEX_COMPILER_FLAGS} ${synctex_flags} ${LATEX_MAIN_INPUT}
    968     )
    969 
    970   # Set up target names.
    971   IF (LATEX_MANGLE_TARGET_NAMES)
    972     SET(dvi_target      ${LATEX_TARGET}_dvi)
    973     SET(pdf_target      ${LATEX_TARGET}_pdf)
    974     SET(ps_target       ${LATEX_TARGET}_ps)
    975     SET(safepdf_target  ${LATEX_TARGET}_safepdf)
    976     SET(html_target     ${LATEX_TARGET}_html)
    977     SET(auxclean_target ${LATEX_TARGET}_auxclean)
    978   ELSE (LATEX_MANGLE_TARGET_NAMES)
    979     SET(dvi_target      dvi)
    980     SET(pdf_target      pdf)
    981     SET(ps_target       ps)
    982     SET(safepdf_target  safepdf)
    983     SET(html_target     html)
    984     SET(auxclean_target auxclean)
    985   ENDIF (LATEX_MANGLE_TARGET_NAMES)
    986 
    987   # Probably not all of these will be generated, but they could be.
    988   # Note that the aux file is added later.
    989   SET(auxiliary_clean_files
    990     ${output_dir}/${LATEX_TARGET}.bbl
    991     ${output_dir}/${LATEX_TARGET}.blg
    992     ${output_dir}/${LATEX_TARGET}-blx.bib
    993     ${output_dir}/${LATEX_TARGET}.glg
    994     ${output_dir}/${LATEX_TARGET}.glo
    995     ${output_dir}/${LATEX_TARGET}.gls
    996     ${output_dir}/${LATEX_TARGET}.idx
    997     ${output_dir}/${LATEX_TARGET}.ilg
    998     ${output_dir}/${LATEX_TARGET}.ind
    999     ${output_dir}/${LATEX_TARGET}.ist
   1000     ${output_dir}/${LATEX_TARGET}.log
   1001     ${output_dir}/${LATEX_TARGET}.out
   1002     ${output_dir}/${LATEX_TARGET}.toc
   1003     ${output_dir}/${LATEX_TARGET}.lof
   1004     ${output_dir}/${LATEX_TARGET}.xdy
   1005     ${output_dir}/${LATEX_TARGET}.synctex.gz
   1006     ${output_dir}/${LATEX_TARGET}.synctex.bak.gz
   1007     ${output_dir}/${LATEX_TARGET}.dvi
   1008     ${output_dir}/${LATEX_TARGET}.ps
   1009     ${output_dir}/${LATEX_TARGET}.pdf
   1010     )
   1011 
   1012   SET(image_list ${LATEX_IMAGES})
   1013 
   1014   # For each directory in LATEX_IMAGE_DIRS, glob all the image files and
   1015   # place them in LATEX_IMAGES.
   1016   FOREACH(dir ${LATEX_IMAGE_DIRS})
   1017     IF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
   1018       MESSAGE(WARNING "Image directory ${CMAKE_CURRENT_SOURCE_DIR}/${dir} does not exist.  Are you sure you gave relative directories to IMAGE_DIRS?")
   1019     ENDIF (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
   1020     FOREACH(extension ${LATEX_IMAGE_EXTENSIONS})
   1021       FILE(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*${extension})
   1022       FOREACH(file ${files})
   1023         LATEX_GET_FILENAME_COMPONENT(filename ${file} NAME)
   1024         SET(image_list ${image_list} ${dir}/${filename})
   1025       ENDFOREACH(file)
   1026     ENDFOREACH(extension)
   1027   ENDFOREACH(dir)
   1028 
   1029   LATEX_PROCESS_IMAGES(dvi_images pdf_images ${image_list})
   1030 
   1031   SET(make_dvi_command
   1032     ${CMAKE_COMMAND} -E chdir ${output_dir}
   1033     ${latex_build_command})
   1034   SET(make_pdf_command
   1035     ${CMAKE_COMMAND} -E chdir ${output_dir}
   1036     ${pdflatex_build_command}
   1037     )
   1038 
   1039   SET(make_dvi_depends ${LATEX_DEPENDS} ${dvi_images})
   1040   SET(make_pdf_depends ${LATEX_DEPENDS} ${pdf_images})
   1041   FOREACH(input ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
   1042     SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${input})
   1043     SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${input})
   1044     IF (${input} MATCHES "\\.tex$")
   1045       STRING(REGEX REPLACE "\\.tex$" "" input_we ${input})
   1046       SET(auxiliary_clean_files ${auxiliary_clean_files}
   1047         ${output_dir}/${input_we}.aux
   1048         ${output_dir}/${input}.aux
   1049         )
   1050     ENDIF (${input} MATCHES "\\.tex$")
   1051   ENDFOREACH(input)
   1052 
   1053   IF (LATEX_USE_GLOSSARY)
   1054     FOREACH(dummy 0 1)   # Repeat these commands twice.
   1055       SET(make_dvi_command ${make_dvi_command}
   1056         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1057         ${CMAKE_COMMAND}
   1058         -D LATEX_BUILD_COMMAND=makeglossaries
   1059         -D LATEX_TARGET=${LATEX_TARGET}
   1060         -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
   1061         -D XINDY_COMPILER=${XINDY_COMPILER}
   1062         -D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
   1063         -P ${LATEX_USE_LATEX_LOCATION}
   1064         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1065         ${latex_build_command}
   1066         )
   1067       SET(make_pdf_command ${make_pdf_command}
   1068         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1069         ${CMAKE_COMMAND}
   1070         -D LATEX_BUILD_COMMAND=makeglossaries
   1071         -D LATEX_TARGET=${LATEX_TARGET}
   1072         -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
   1073         -D XINDY_COMPILER=${XINDY_COMPILER}
   1074         -D MAKEGLOSSARIES_COMPILER_FLAGS=${MAKEGLOSSARIES_COMPILER_FLAGS}
   1075         -P ${LATEX_USE_LATEX_LOCATION}
   1076         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1077         ${pdflatex_build_command}
   1078         )
   1079     ENDFOREACH(dummy)
   1080   ENDIF (LATEX_USE_GLOSSARY)
   1081 
   1082   IF (LATEX_USE_NOMENCL)
   1083     FOREACH(dummy 0 1)   # Repeat these commands twice.
   1084       SET(make_dvi_command ${make_dvi_command}
   1085         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1086         ${CMAKE_COMMAND}
   1087         -D LATEX_BUILD_COMMAND=makenomenclature
   1088         -D LATEX_TARGET=${LATEX_TARGET}
   1089         -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
   1090         -D MAKENOMENCLATURE_COMPILER_FLAGS=${MAKENOMENCLATURE_COMPILER_FLAGS}
   1091         -P ${LATEX_USE_LATEX_LOCATION}
   1092         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1093         ${latex_build_command}
   1094         )
   1095       SET(make_pdf_command ${make_pdf_command}
   1096         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1097         ${CMAKE_COMMAND}
   1098         -D LATEX_BUILD_COMMAND=makenomenclature
   1099         -D LATEX_TARGET=${LATEX_TARGET}
   1100         -D MAKEINDEX_COMPILER=${MAKEINDEX_COMPILER}
   1101         -D MAKENOMENCLATURE_COMPILER_FLAGS=${MAKENOMENCLATURE_COMPILER_FLAGS}
   1102         -P ${LATEX_USE_LATEX_LOCATION}
   1103         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1104         ${pdflatex_build_command}
   1105         )
   1106     ENDFOREACH(dummy)
   1107   ENDIF (LATEX_USE_NOMENCL)
   1108 
   1109   IF (LATEX_BIBFILES)
   1110     IF (LATEX_MULTIBIB_NEWCITES)
   1111       FOREACH (multibib_auxfile ${LATEX_MULTIBIB_NEWCITES})
   1112         LATEX_GET_FILENAME_COMPONENT(multibib_target ${multibib_auxfile} NAME_WE)
   1113         SET(make_dvi_command ${make_dvi_command}
   1114           COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1115           ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${multibib_target})
   1116         SET(make_pdf_command ${make_pdf_command}
   1117           COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1118           ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${multibib_target})
   1119         SET(auxiliary_clean_files ${auxiliary_clean_files}
   1120           ${output_dir}/${multibib_target}.aux)
   1121       ENDFOREACH (multibib_auxfile ${LATEX_MULTIBIB_NEWCITES})
   1122     ELSE (LATEX_MULTIBIB_NEWCITES)
   1123       SET(make_dvi_command ${make_dvi_command}
   1124         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1125         ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
   1126       SET(make_pdf_command ${make_pdf_command}
   1127         COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1128         ${BIBTEX_COMPILER} ${BIBTEX_COMPILER_FLAGS} ${LATEX_TARGET})
   1129     ENDIF (LATEX_MULTIBIB_NEWCITES)
   1130 
   1131     FOREACH (bibfile ${LATEX_BIBFILES})
   1132       SET(make_dvi_depends ${make_dvi_depends} ${output_dir}/${bibfile})
   1133       SET(make_pdf_depends ${make_pdf_depends} ${output_dir}/${bibfile})
   1134     ENDFOREACH (bibfile ${LATEX_BIBFILES})
   1135   ELSE (LATEX_BIBFILES)
   1136     IF (LATEX_MULTIBIB_NEWCITES)
   1137       MESSAGE(WARNING "MULTIBIB_NEWCITES has no effect without BIBFILES option.")
   1138     ENDIF (LATEX_MULTIBIB_NEWCITES)
   1139   ENDIF (LATEX_BIBFILES)
   1140 
   1141   IF (LATEX_USE_INDEX)
   1142     SET(make_dvi_command ${make_dvi_command}
   1143       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1144       ${latex_build_command}
   1145       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1146       ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
   1147     SET(make_pdf_command ${make_pdf_command}
   1148       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1149       ${pdflatex_build_command}
   1150       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1151       ${MAKEINDEX_COMPILER} ${MAKEINDEX_COMPILER_FLAGS} ${LATEX_TARGET}.idx)
   1152   ENDIF (LATEX_USE_INDEX)
   1153 
   1154   SET(make_dvi_command ${make_dvi_command}
   1155     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1156     ${latex_build_command}
   1157     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1158     ${latex_build_command})
   1159   SET(make_pdf_command ${make_pdf_command}
   1160     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1161     ${pdflatex_build_command}
   1162     COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1163     ${pdflatex_build_command})
   1164 
   1165   IF (LATEX_USE_SYNCTEX)
   1166     IF (NOT GZIP)
   1167       MESSAGE(SEND_ERROR "UseLATEX.cmake: USE_SYNTEX option requires gzip program.  Set GZIP variable.")
   1168     ENDIF (NOT GZIP)
   1169     SET(make_dvi_command ${make_dvi_command}
   1170       COMMAND ${CMAKE_COMMAND}
   1171       -D LATEX_BUILD_COMMAND=correct_synctex
   1172       -D LATEX_TARGET=${LATEX_TARGET}
   1173       -D GZIP=${GZIP}
   1174       -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
   1175       -D "LATEX_BINARY_DIRECTORY=${output_dir}"
   1176       -P ${LATEX_USE_LATEX_LOCATION}
   1177       )
   1178     SET(make_pdf_command ${make_pdf_command}
   1179       COMMAND ${CMAKE_COMMAND}
   1180       -D LATEX_BUILD_COMMAND=correct_synctex
   1181       -D LATEX_TARGET=${LATEX_TARGET}
   1182       -D GZIP=${GZIP}
   1183       -D "LATEX_SOURCE_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
   1184       -D "LATEX_BINARY_DIRECTORY=${output_dir}"
   1185       -P ${LATEX_USE_LATEX_LOCATION}
   1186       )
   1187   ENDIF (LATEX_USE_SYNCTEX)
   1188 
   1189   # Add commands and targets for building dvi outputs.
   1190   ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.dvi
   1191     COMMAND ${make_dvi_command}
   1192     DEPENDS ${make_dvi_depends}
   1193     VERBATIM
   1194     )
   1195   IF (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
   1196     ADD_CUSTOM_TARGET(${dvi_target}
   1197       DEPENDS ${output_dir}/${LATEX_TARGET}.dvi VERBATIM)
   1198   ELSE (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
   1199     ADD_CUSTOM_TARGET(${dvi_target}
   1200       DEPENDS ${output_dir}/${LATEX_TARGET}.dvi VERBATIM)
   1201   ENDIF (LATEX_DEFAULT_PDF OR LATEX_DEFAULT_SAFEPDF)
   1202 
   1203   # Add commands and targets for building pdf outputs (with pdflatex).
   1204   IF (PDFLATEX_COMPILER)
   1205     ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.pdf
   1206       COMMAND ${make_pdf_command}
   1207       DEPENDS ${make_pdf_depends}
   1208       VERBATIM
   1209       )
   1210     IF (LATEX_DEFAULT_PDF)
   1211       ADD_CUSTOM_TARGET(${pdf_target}
   1212         DEPENDS ${output_dir}/${LATEX_TARGET}.pdf VERBATIM)
   1213     ELSE (LATEX_DEFAULT_PDF)
   1214       ADD_CUSTOM_TARGET(${pdf_target}
   1215         DEPENDS ${output_dir}/${LATEX_TARGET}.pdf VERBATIM)
   1216     ENDIF (LATEX_DEFAULT_PDF)
   1217   ENDIF (PDFLATEX_COMPILER)
   1218 
   1219   IF (DVIPS_CONVERTER)
   1220     ADD_CUSTOM_COMMAND(OUTPUT ${output_dir}/${LATEX_TARGET}.ps
   1221       COMMAND ${CMAKE_COMMAND} -E chdir ${output_dir}
   1222         ${DVIPS_CONVERTER} ${DVIPS_CONVERTER_FLAGS} -o ${LATEX_TARGET}.ps ${LATEX_TARGET}.dvi
   1223       DEPENDS ${output_dir}/${LATEX_TARGET}.dvi VERBATIM)
   1224     ADD_CUSTOM_TARGET(${ps_target}
   1225       DEPENDS ${output_dir}/${LATEX_TARGET}.ps VERBATIM)
   1226     IF (PS2PDF_CONVERTER)
   1227       # Since both the pdf and safepdf targets have the same output, we
   1228       # cannot properly do the dependencies for both.  When selecting safepdf,
   1229       # simply force a recompile every time.
   1230       IF (LATEX_DEFAULT_SAFEPDF)
   1231         ADD_CUSTOM_TARGET(${safepdf_target}
   1232           ${CMAKE_COMMAND} -E chdir ${output_dir}
   1233           ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
   1234           VERBATIM
   1235           )
   1236       ELSE (LATEX_DEFAULT_SAFEPDF)
   1237         ADD_CUSTOM_TARGET(${safepdf_target}
   1238           ${CMAKE_COMMAND} -E chdir ${output_dir}
   1239           ${PS2PDF_CONVERTER} ${PS2PDF_CONVERTER_FLAGS} ${LATEX_TARGET}.ps ${LATEX_TARGET}.pdf
   1240           VERBATIM
   1241           )
   1242       ENDIF (LATEX_DEFAULT_SAFEPDF)
   1243       ADD_DEPENDENCIES(${safepdf_target} ${ps_target})
   1244     ENDIF (PS2PDF_CONVERTER)
   1245   ENDIF (DVIPS_CONVERTER)
   1246 
   1247   IF (LATEX2HTML_CONVERTER)
   1248     ADD_CUSTOM_TARGET(${html_target}
   1249       ${CMAKE_COMMAND} -E chdir ${output_dir}
   1250       ${LATEX2HTML_CONVERTER} ${LATEX2HTML_CONVERTER_FLAGS} ${LATEX_MAIN_INPUT}
   1251       VERBATIM
   1252       )
   1253     ADD_DEPENDENCIES(${html_target} ${LATEX_MAIN_INPUT} ${LATEX_INPUTS})
   1254   ENDIF (LATEX2HTML_CONVERTER)
   1255 
   1256   SET_DIRECTORY_PROPERTIES(.
   1257     ADDITIONAL_MAKE_CLEAN_FILES "${auxiliary_clean_files}"
   1258     )
   1259 
   1260   ADD_CUSTOM_TARGET(${auxclean_target}
   1261     COMMENT "Cleaning auxiliary LaTeX files."
   1262     COMMAND ${CMAKE_COMMAND} -E remove ${auxiliary_clean_files}
   1263     VERBATIM
   1264     )
   1265 ENDFUNCTION(ADD_LATEX_TARGETS_INTERNAL)
   1266 
   1267 FUNCTION(ADD_LATEX_TARGETS)
   1268   LATEX_GET_OUTPUT_PATH(output_dir)
   1269   PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_TARGETS ${ARGV})
   1270 
   1271   ADD_LATEX_TARGETS_INTERNAL()
   1272 ENDFUNCTION(ADD_LATEX_TARGETS)
   1273 
   1274 FUNCTION(ADD_LATEX_DOCUMENT)
   1275   LATEX_GET_OUTPUT_PATH(output_dir)
   1276   IF (output_dir)
   1277     PARSE_ADD_LATEX_ARGUMENTS(ADD_LATEX_DOCUMENT ${ARGV})
   1278 
   1279     LATEX_COPY_INPUT_FILE(${LATEX_MAIN_INPUT})
   1280 
   1281     FOREACH (bib_file ${LATEX_BIBFILES})
   1282       LATEX_COPY_INPUT_FILE(${bib_file})
   1283     ENDFOREACH (bib_file)
   1284 
   1285     FOREACH (input ${LATEX_INPUTS})
   1286       LATEX_COPY_INPUT_FILE(${input})
   1287     ENDFOREACH(input)
   1288 
   1289     LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.cls ${output_dir})
   1290     LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.bst ${output_dir})
   1291     LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.clo ${output_dir})
   1292     LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.sty ${output_dir})
   1293     LATEX_COPY_GLOBBED_FILES(${CMAKE_CURRENT_SOURCE_DIR}/*.ist ${output_dir})
   1294 
   1295     ADD_LATEX_TARGETS_INTERNAL()
   1296   ENDIF (output_dir)
   1297 ENDFUNCTION(ADD_LATEX_DOCUMENT)
   1298 
   1299 #############################################################################
   1300 # Actually do stuff
   1301 #############################################################################
   1302 
   1303 IF (LATEX_BUILD_COMMAND)
   1304   SET(command_handled)
   1305 
   1306   IF ("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
   1307     LATEX_MAKEGLOSSARIES()
   1308     SET(command_handled TRUE)
   1309   ENDIF ("${LATEX_BUILD_COMMAND}" STREQUAL makeglossaries)
   1310 
   1311   IF ("${LATEX_BUILD_COMMAND}" STREQUAL makenomenclature)
   1312     LATEX_MAKENOMENCLATURE()
   1313     SET(command_handled TRUE)
   1314   ENDIF ("${LATEX_BUILD_COMMAND}" STREQUAL makenomenclature)
   1315 
   1316   IF ("${LATEX_BUILD_COMMAND}" STREQUAL correct_synctex)
   1317     LATEX_CORRECT_SYNCTEX()
   1318     SET(command_handled TRUE)
   1319   ENDIF ("${LATEX_BUILD_COMMAND}" STREQUAL correct_synctex)
   1320 
   1321   IF (NOT command_handled)
   1322     MESSAGE(SEND_ERROR "Unknown command: ${LATEX_BUILD_COMMAND}")
   1323   ENDIF (NOT command_handled)
   1324 
   1325 ELSE (LATEX_BUILD_COMMAND)
   1326   # Must be part of the actual configure (included from CMakeLists.txt).
   1327   LATEX_SETUP_VARIABLES()
   1328 ENDIF (LATEX_BUILD_COMMAND)