Menu

#580 mp: insert "outputtemplate" line

None
closed-accepted
nobody
5
2025-03-28
2024-10-10
No

In MetaPost it is often desirable to create an output file with extension ".mps" instead of the default ".0" . This can be done by inserting a line 'outputtemplate:="%j.mps";' in the mp file. Gnuplot doesn't do this, but can be easily extended to accept a new boolean. In the attached file I implemented this behaviour, including an update of the help file.

1 Attachments

Related

Feature Requests: #580

Discussion

  • Ethan Merritt

    Ethan Merritt - 2024-10-11
    • Group: -->
     
    • Edgar Olthof

      Edgar Olthof - 2024-10-11

      Hi Ethan,

      Thanks for looking into this.
      I see it doesn't work for me either, but that has nothing to do with the
      'template' boolean; it's due to the simple.dem file. It specifies font ",20"
      and metapost chokes on that, because the name of the font (which is "" then)
      was not recognised. Removed it, and everything went smooth.
      I indeed cut a corner by setting outputtemplate:="%j.mps"; multiple plots
      are then written to the same file, effectively erasing all but the last. I had
      better set something like outputtemplate:="%j_%c.mps"; in which case separate
      files will be created. Try it out in simple.mp.
      To answer your question on why using metapost in the first place: the step
      from LaTeX to pdf, while including pictures is done easiest when the pictures
      themselves are pdf, but the next best thing is via mps because it can use TeX
      fonts (much more difficult via eps). And since creating nice pictures is (or
      was) best done with metapost, this was the natural way for me for a long time.
      Let me fix it all, including an update of the help docs. May take some
      time... I'll get back on this.
      Thanks for your help. Gnuplot is great.

      Best regards,

      Edgar

      On Friday, 11 October 2024 06:30:59 CEST you wrote:

      • Group: -->
      • Comment:

      Doesn't work for me. If I use
      ~~~
      set term mp template prologue 2
      set output 'simple.mp'
      load 'simple.dem'
      ~~~
      then when I run the output file simple.mp through mpost I get errors printed
      on the console (appended below) and a single output file named simple.mpx .

      When I run it without the "template" option I get the expected output file
      simple.0 simple.1 simple.2 and so on.

      I have never used metapost myself so I can only guess that the template for
      file names needs to be more complicated than that to handle multiple output
      files.

      ~~~
      This is MetaPost, version 2.02 (TeX Live 2022/Mageia) (kpathsea version
      6.3.4) (/usr/share/texmf-dist/metapost/base/mpost.mp
      (/usr/share/texmf-dist/metapost/base/plain.mp
      Preloading the plain mem file, version 1.005) ) (./simple.mpfatal: Command
      failed: etex --parse-first-line --interaction=nonstopmode mpdWC6CJ.tex; see
      mpxerr.log

      simple.mp
      simple.mpx

      ! ! Unable to read mpx file.
      l.129 put_text( btex
      $-1.5$ etex, 97.3a, 73.2b, 0, 3);
      Transcript written on simple.log.
      ~~~

      **Just to satisfy my curiosity... **

      I thought metapost was long dead and gone. The gnuplot terminal for it has
      not been updated for about 20 years. I can understand that 20 years ago it
      offered options that were not easily achieved by the other TeX-related
      output modes, but are any of those still relevant? Why would one choose
      metapost rather than, say, pgf/tikz (gnuplot set terminal tikz)? Or if
      you really want epsf files, then maybe set term cairolatex eps?

      If there are good reasons to use metapost these days, could you maybe
      suggest some text to update the description in the docs left over from 20
      years ago?


      [feature-requests:#580] mp: insert "outputtemplate" line

      Status: open
      Group:
      Labels: Feature request
      Created: Thu Oct 10, 2024 07:07 PM UTC by Edgar Olthof
      Last Updated: Thu Oct 10, 2024 07:07 PM UTC
      Owner: nobody
      Attachments:

      -
      metapost.trm (39.7 kB; application/octet-stream)

      In MetaPost it is often desirable to create an output file with extension
      ".mps" instead of the default ".0" . This can be done by inserting a line
      'outputtemplate:="%j.mps";' in the mp file. Gnuplot doesn't do this, but
      can be easily extended to accept a new boolean. In the attached file I
      implemented this behaviour, including an update of the help file.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/gnuplot/feature-requests/580/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

      --
      Edgar Olthof
      Galvanistraat 14
      6533 DW Nijmegen
      tel.: 024 3565522

       

      Related

      Feature Requests: #580

      • Ethan Merritt

        Ethan Merritt - 2024-10-11

        The font problem makes sense and is easily fixable. In fact the existing code handles a blank font correctly in one place but gets it wrong in another place. After changing that and modifying the template format it seems to work here. So what I have is probably acceptable but I'll wait and compare it to your updated version.

         
        • Edgar Olthof

          Edgar Olthof - 2024-10-13

          Hi Ethan,

          A working version is available, see the attachments. In it I implemented the
          "template" option with a mandatory argument. I also fixed the bug on the font
          problem, so running simple.gp in the demo directory should now run smoothly,
          at least it does so at my side. The documentation is also updated
          accordingly.
          When you're fine with this, I can upload the file metapost.trm to
          sourcefourge.

          Best regards,

          Edgar

          On Friday, 11 October 2024 20:16:32 CEST you wrote:

          The font problem makes sense and is easily fixable. In fact the existing
          code handles a blank font correctly in one place but gets it wrong in
          another place. After changing that and modifying the template format it
          seems to work here. So what I have is probably acceptable but I'll wait
          and compare it to your updated version.


          [feature-requests:#580] mp: insert "outputtemplate" line

          Status: open
          Group:
          Labels: Feature request
          Created: Thu Oct 10, 2024 07:07 PM UTC by Edgar Olthof
          Last Updated: Fri Oct 11, 2024 04:30 AM UTC
          Owner: nobody
          Attachments:

          -
          metapost.trm (39.7 kB; application/octet-stream)

          In MetaPost it is often desirable to create an output file with extension
          ".mps" instead of the default ".0" . This can be done by inserting a line
          'outputtemplate:="%j.mps";' in the mp file. Gnuplot doesn't do this, but
          can be easily extended to accept a new boolean. In the attached file I
          implemented this behaviour, including an update of the help file.


          Sent from sourceforge.net because you indicated interest in
          https://sourceforge.net/p/gnuplot/feature-requests/580/

          To unsubscribe from further messages, please visit
          https://sourceforge.net/auth/subscriptions/

          --
          Edgar Olthof
          Galvanistraat 14
          6533 DW Nijmegen
          tel.: 024 3565522

           

          Related

          Feature Requests: #580

          • Ethan Merritt

            Ethan Merritt - 2024-10-14

            Simple test works here, but I would like another round of cleanup

            comments on your revised source file of 13 Oct 2024

            • Please do not collapse the first two lines of function definitions. The style used in gnuplot source always places the name of the function being defined in the first column of a new line. Like this:
            static foo *
            my_function( int param1, int param2)
            {
            ... body of function ...
            }
            
            • Also please do not change the tab/indentation everywhere. It makes it hard to see what has really changed when practivally every line is different. Gnuplot source style is tab=4 spaces.

            • The code reading in the template string is way more complicated than it needs to be. No separate flag variable or static character array is necessary. It should be sufficient to do something like this:

            static char *MP_template = NULL;
            ... 
            case MP_OPT_TEMPLATE: 
                free(MP_template);
                MP_template = try_to_get_string();
            ...
              if (MP_template)
                  fprintf(gpoutfile,"filenametemplate \"%s\";\n",MP_template);
             ...
            
            • Except that the documentation I found on tug.org says that the syntax filenametemplate "xxx" has been deprecated and instead one should use
              outputtemplate:="xxx"

            • Maybe if the user gives the keyword template with no string afterward the program should use a default template string rather than failing via int_error()?

            I appreciate your contribution of code. Would your use of the metapost terminal benefit from further updates to support gnuplot features added in versions 4/5/6? User-specified colors perhaps? Polygon fill?

             
            • Edgar Olthof

              Edgar Olthof - 2024-10-18

              Hi Ethan,

              Thanks for your comments. I changed the file accordingly: it now includes your
              code for ending a rectangle by "--cycle;" (ticket 2738), my code for
              implementing the "template" option, including help texts (feature request
              580---this thread), a change in MP_set_font() solving a bug that prevented
              simple.dem from running correctly, and a small cleanup of the MP_put_text()
              code; nothing else.
              I'll have a look at your last request on user-specified colors and polygon
              fill.

              Best regards,

              Edgar

              On Monday, 14 October 2024 08:15:17 CEST you wrote:

              Simple test works here, but I would like another round of cleanup

              I appreciate your contribution of code. Would your use of the metapost
              terminal benefit from further updates to support gnuplot features added in
              versions 4/5/6? User-specified colors perhaps? Polygon fill?


              [feature-requests:#580] mp: insert "outputtemplate" line

              Status: open
              Group:
              Labels: Feature request
              Created: Thu Oct 10, 2024 07:07 PM UTC by Edgar Olthof
              Last Updated: Fri Oct 11, 2024 06:16 PM UTC
              Owner: nobody
              Attachments:

              -
              metapost.trm (39.7 kB; application/octet-stream)

              In MetaPost it is often desirable to create an output file with extension
              ".mps" instead of the default ".0" . This can be done by inserting a line
              'outputtemplate:="%j.mps";' in the mp file. Gnuplot doesn't do this, but
              can be easily extended to accept a new boolean. In the attached file I
              implemented this behaviour, including an update of the help file.

               

              Related

              Feature Requests: #580

              • Ethan Merritt

                Ethan Merritt - 2024-10-18

                Looks good. I've committed it to the development branch. I plan to revise the build scripts to add back the metapost terminal documentation to the PDF and HTML user manual if the terminal is configured in.

                 
  • Ethan Merritt

    Ethan Merritt - 2024-10-11

    Doesn't work for me. If I use

        set term mp template prologue 2
        set output 'simple.mp'
        load 'simple.dem'
    

    then when I run the output file simple.mp through mpost I get errors printed on the console (appended below) and a single output file named simple.mpx .

    When I run it without the "template" option I get the expected output file simple.0 simple.1 simple.2 and so on.

    I have never used metapost myself so I can only guess that the template for file names needs to be more complicated than that to handle multiple output files.

    This is MetaPost, version 2.02 (TeX Live 2022/Mageia) (kpathsea version 6.3.4)
    (/usr/share/texmf-dist/metapost/base/mpost.mp
    (/usr/share/texmf-dist/metapost/base/plain.mp
    Preloading the plain mem file, version 1.005) ) (./simple.mpfatal: Command failed: etex --parse-first-line --interaction=nonstopmode mpdWC6CJ.tex; see mpxerr.log
    >> simple.mp
    >> simple.mpx
     ! ! Unable to read mpx file.
     l.129 put_text( btex
                          $-1.5$ etex, 97.3a, 73.2b, 0, 3);
    Transcript written on simple.log.
    

    **Just to satisfy my curiosity... **

    I thought metapost was long dead and gone. The gnuplot terminal for it has not been updated for about 20 years. I can understand that 20 years ago it offered options that were not easily achieved by the other TeX-related output modes, but are any of those still relevant? Why would one choose metapost rather than, say, pgf/tikz (gnuplot set terminal tikz)? Or if you really want epsf files, then maybe set term cairolatex eps?

    If there are good reasons to use metapost these days, could you maybe suggest some text to update the description in the docs left over from 20 years ago?

     
  • Ethan Merritt

    Ethan Merritt - 2025-03-28
    • status: open --> closed-accepted
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.