shiblon / latex-makefile

A Makefile for LaTeX - drop it in, type make, and magic happens.
Other
185 stars 30 forks source link

Add support for creating metapost files #149

Open shiblon opened 8 years ago

shiblon commented 8 years ago

Originally reported on Google Code with ID 136

Hi!

Is it possible to add support for metapost files?

For example when using the feynmf package I have to run pdflatex once for the creation
of .mp files, on which I need to call mpost file.mp. After that, the final pdflatex
run can be done.

Regards, Tobias

Reported by tobias.neumann on 2011-07-26 19:44:33

shiblon commented 8 years ago
Hi Chris,

I also use Metapost graphics for my dissertation, and it would be a very handy additional
feature to include support.  I believe that it may only be necessary to change the
Makefile for BUILD-STRATEGY := latex.

When I compile my Metapost source files, the output file gets a .mps extension.  Interestingly,
these .mps files are useful because they can be called (omitting the extension) whether
the document is processed with LaTeX or pdfLaTex.

From this TUGboat article on Metapost
(http://www.tug.org/TUGboat/Articles/tb30-2/tb95hoeppner.pdf):

"...the PostScript subset created by METAPOST can be interpreted by pdfTeX. So METAPOST
figures can be directly included with e. g. the standard graphics package, while normal
EPS images have to be converted first to be usable with pdfLaTeX."

When running Makefile (2.2.0) on a document that contains calls to .mps files, there
is different behavior for pdfLaTeX and for regular LaTeX.

For BUILD-STRATEGY := pdflatex, things work great, and the pdf is built as it should
be with the included graphic.  No problems!

For BUILD-STRATEGY := latex, the result is "no rule to make target foo...", although
there is a workaround: if one changes the name of the graphic file from foo.mps to
foo.eps, then the compilation will proceed as it should.

When using BUILD-STRATEGY := latex, I once tried to workaround by setting includes.eps
:= foo.mps in Variables.ini, but still got the "no rule to make..."

I hope this info helps!  Thanks again very much for sharing continuing to develop your
Makefile.

Sincerely,
Chas

Reported by charles.hewgley4 on 2011-08-08 22:38:43

shiblon commented 8 years ago
If I understand correctly, there is nothing to be done for BUILD_STRATEGY=pdflatex,
right?

So, for strategy "latex", we have the following issue:

- The .mps files are built correctly,
- The makefile is properly inserting dependencies on "foo", but
- Doesn't know how to build foo.eps from foo.mps, so
- It fails, even though it should work.

Correct?

Can you try adding the following (use tabs, not spaces) to your Makefile.ini and let
me know how it works?

%.eps: %.mps
  $(CP) '$<' '$@'

Reported by shiblon on 2011-08-09 16:38:48

shiblon commented 8 years ago
Thanks for the follow-up!  I now realize that I omitted the important fact that in my
last post, I was assuming that the .mps (Metapost postscript output) files had already
been created manually from the .mp (Metapost source) files using the command 'mpost
foo.mp'.  That's how I generally do it, but I realize now that the original poster
might have wanted the makefile to ascertain that foo.mp was a Metapost source, and
then call 'mpost foo.mp' to create a .mps file which would then be included in the
LaTeX file.

For now, I'll continue assuming that the .mps files are already created when make is
invoked.  So, for strategy = "pdflatex", if the file foo.mps already exists, a statement
such as \includegraphics{foo} works properly, and the document is built with the graphic.

For strategy = "latex" I added the new rule from your last comment to my Makefile.ini,
but still received the message:
= my_latex.tex --> my_latex.d my_latex.dvi.1st.make (0-1) =
make: *** No rule to make target `foo', needed by `my_latex.d'.  Stop.

Interestingly, if I first issued the command 'make foo.eps', then the correct copy
command was invoked, creating 'foo.eps', then I could issue a subsequent make command
and the document would be built correctly.

But, if I only issued 'make', without first issuing 'make foo.eps,' then I got 'no
rule to make target.'  It seems that make was not figuring out that a statement such
as \includegraphics{foo} could ultimately depend on a .mps file... so maybe the correct
dependencies are not made after all?

I've attached a file 'foo.mps' in case it might be helpful.

Thanks again!

Reported by charles.hewgley4 on 2011-08-10 05:29:36


shiblon commented 8 years ago
Aha.  I see what I did wrong.  I forgot to tell you to add this at the top of your Targets.ini
file:

graphic_source_extensions += mps

Reported by shiblon on 2011-08-10 13:42:02

shiblon commented 8 years ago
OK, that worked!  Now, make with strategy "latex" can recognize an already-existing
Metapost postscript .mps file, copy that into a .eps file, and then build the document
properly with the .eps file.

Reported by charles.hewgley4 on 2011-08-10 17:20:28

shiblon commented 8 years ago
All right.  That's a good step forward.  Let's keep track of that as working by summarizing
what we did here, then we can discuss what comes next.

===========================
What we did:
===========================

Add to Targets.ini the following lines:

graphic_source_extensions += mps
%.eps: %.mps
  $(CP) '$<' '$@'

=================
What's next
=================

Next we need to make sure that both build strategies (latex and pdflatex) can detect
when a .mps file needs to be generated from a .mp file, and we need to create a .mp
-> .mps build rule that can do it.

The last step is the easiest (again with tabs, not spaces):

%.mps: %.mp
  mpost $<

Of course, we'll do a lot more than that, since it's going to generate a lot of output
and we'll want to catch errors, etc.  It will probably be set up in its own definition,
and will call mpost and then run sed on the output to catch issues.  That's pretty
straightforward.

The not-so-straightforward stuff comes in detection.  Since we're just doing includegraphics
on it, I *think* the need will be detected correctly, but I'm not sure.

============================
What would help
============================

If someone could attach a minimal tarball containing a .tex source file and some .mp
files that it tries to include, I can work on getting this up and running.  Shouldn't
take too long, but real logs made from real source are invaluable to the process. 
I just don't particularly feel like learning metapost to generate my own .mp files
at the moment.  :-)

Reported by shiblon on 2011-08-10 17:32:11

shiblon commented 8 years ago
OK, here is a very simple, one-page latex document that includes two Metapost graphics.
 So, initially, one would need to run mpost first on the two Metapost source files,
then compile the latex file -- that is, until the Makefile does it all automatically
:)
Thanks much!

Reported by charles.hewgley4 on 2011-08-10 19:26:49


shiblon commented 8 years ago
Here is a minimal example where the problems occur:

\documentclass{scrreprt}
\usepackage{feynmp}
\DeclareGraphicsRule{*}{mps}{*}{}
\begin{document}
\begin{fmffile}{feyntest}
\begin{fmfgraph*}(100,60)
    \fmfleft{a}
    \fmfright{b}
    \fmf{fermion,label={test}}{a,b}
\end{fmfgraph*}
\end{fmffile}
\end{document}

I use make; then need to call mpost feyntest.mp to create the graphics file. Then I
run make again which works but further invocations fail because the Makefile tries
to make a pdf file from the created graphics:

make: *** No rule to make target `feyntest.1.pdf', needed by `test.pdf'.  Stop.

To circument this as a temporary bugfix I removed the get-graphics call:
-   $(call get-graphics,$*) >> $*.d; \

Reported by tobias.neumann on 2011-08-16 08:51:30

shiblon commented 8 years ago
Hey, tobias - sorry for disappearing for a while.  Unfortunately, your minimal example
is a little too minimal for little old me :).  What is feynmp, and where can I get
feyntest.mp to fiddle with it?

Reported by shiblon on 2011-09-06 20:17:05

shiblon commented 8 years ago
tobias - never mind.  I see that you're generating feyntest.mp from within the .tex.
 I'm still not sure about the feynmp package, though

Reported by shiblon on 2011-09-06 20:18:57

shiblon commented 8 years ago
This is the feynmf package: http://www.ctan.org/tex-archive/macros/latex/contrib/feynmf
or if you have a debian basted distro use the package feynmf.

Reported by tobias.neumann on 2011-09-06 21:01:49

shiblon commented 8 years ago
Thanks, tobias.

Meanwhile, I think I have initial, basic support for mp files included via \includegraphics.
 Please see attached.

Reported by shiblon on 2011-09-06 21:16:18