1

Suppose I have a MetaPost code that needs to be exported into multiple formats. According to the MetaPost manual, MetaPost itself can export three different file types (EPS, SVG and PNG).

The "proper" way to specify the output file format is to add a line into the source file:

outputformat := "svg"

But since I want them in multiple formats, I would need a command line option instead of editing the file every time I need to change the output format, and I found the following command:

mpost -s 'outputformat="svg"' xxx.mp

But I get this warning:

Warning: 'outputformat=0: variable does not exist, assignment ignored.

And it only outputs EPS files. Is there a command line option to make it directly output SVG files as it claims?

  • Welcome! What version of Metapost are you running and in what environment? – egreg Nov 30 '19 at 9:00
  • I'm using the Metapost that bundles with MikTeX 2.9, running on Windows. – AngeCI Nov 30 '19 at 10:33
  • That is quite strange; I just tested this and got no such error, and in fact got a perfectly formed svg file. (Though it did have the suffix .1, as usual.) When you run mpost -v, what do you get? Mine indicates 2.00 from TeXLive 2019; I'm not sure what version MikTeX bundles. – dgoodmaniii Nov 30 '19 at 15:14
  • MetaPost 2.000 (MiKTeX 2.9.6500 64-bit) (MiKTeX 2.9.6500 64-bit). – AngeCI Nov 30 '19 at 15:41
0

This appears to be an issue with the shell that is calling mpost rather than an issue with Metapost.

On my main Mac system, I get this:

bash-3.2$ mpost -s outputformat="svg" wavelength.mp
This is MetaPost, version 2.00 (TeX Live 2019) (kpathsea version 6.3.1)
(/usr/local/texlive/2019/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2019/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./wavelength.mp
Warning: outputformat=0: value has the wrong type, assignment ignored.
[1{psfonts.map}<cmr10.pfb>] )
1 output file written: wavelength1.eps
Transcript written on wavelength.log.

which is the same issue that the OP had.

But note that I did not put the argument to -s in single quotes.

If I escape the double quotes it works as expected:

bash-3.2$ mpost -s outputformat=\"svg\" wavelength.mp
This is MetaPost, version 2.00 (TeX Live 2019) (kpathsea version 6.3.1)
(/usr/local/texlive/2019/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2019/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./wavelength.mp [1{psfonts.map
}<cmr10.pfb>] )
1 output file written: wavelength1.svg
Transcript written on wavelength.log.

I can also escape the double quotes with single quotes, and this also works:

bash-3.2$ mpost -s 'outputformat="svg"' wavelength.mp
This is MetaPost, version 2.00 (TeX Live 2019) (kpathsea version 6.3.1)
(/usr/local/texlive/2019/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2019/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./wavelength.mp [1{psfonts.map
}<cmr10.pfb>] )
1 output file written: wavelength1.svg
Transcript written on wavelength.log.

I don't have access to a Windows system to test, but I guess whatever shell the OP was using is "mis-interpreting" the double quotes. Try doubling them? Or using backslash?

Extra note

Incidentally, if you can find the way to pass the quotes to mpost properly, you might like to set this near the top of your MP source:

outputtemplate := "%j%c.%{outputformat}";

This makes mpost use the current output format as the file extension, which is probably what you want.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.