[CMake] Matlab producing image files for use with LaTeX

Moreland, Kenneth kmorel at sandia.gov
Mon Jan 12 11:10:24 EST 2015


Unlike Myles' answer, I'm going to assume that by noticing *.m files have
changed you mean that the changes are picked up when a make build is run,
not necessarily using a daemon to pick up exactly when the change occurs.

You should be able to set a trail of dependencies for make to pick up the
change in the .m file and rebuild accordingly. The first step, of course,
is to make commands to create the pdf file. Then add the output file to
the DEPENDS command of ADD_LATEX_DOCUMENT. Make sure that the pdf file you
create is in the same build directory where the LaTeX command is run so
that your image is picked up. The CMake commands would look something like
this:


add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/MatlabCreated.pdf
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MatlabCreated.m
  COMMAND <matlab command to run MatlabCreated.m and create pdf>
  )

add_latex_document(MyDoc.tex
  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/MatlabCreated.pdf
  )


I don't know Matlab well enough to know whether there is a mechanism to
follow source file dependencies. You could always try writing your own or
Google searching to see if anyone else has done it in CMake, but one step
at a time.

-Ken



On 1/11/15, 1:02 PM, "Rob McDonald" <rob.a.mcdonald at gmail.com> wrote:

>I am familiar with UseLATEX, but would like to take the automation of
>my document build system a step or two further.  Solutions that build
>on UseLATEX -- or a totally separate approach, are OK.
>
>I often use Matlab to create *.pdf figures -- which are then used in a
>LaTeX document.  I would like my build setup to notice when a Matlab
>*.m file has changed - and then re-run it to re-generate the dependent
>*.pdf - and then LaTeX for the final document.
>
>If that works, I would like to take things a step further and specify
>that the *.m files may depend on some external data files of arbitrary
>formats.  The whole system should notice and update when those data
>files are updated.
>
>Bonus points for a system that detects as much of the dependencies
>automagically (like #include ing header files).
>
>Any suggestions?
>
>Rob
>-- 
>
>Powered by www.kitware.com
>
>Please keep messages on-topic and check the CMake FAQ at:
>http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For more
>information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake



More information about the CMake mailing list