7

I would like to use the development version of metapost with luamplib. I've switched over the executable mpost.exe which is presumable called by luamplib somewhere along the line. Now, I would like to pass the option --math=double to mpost.exe so that I can perform calculations on numbers larger than 4096. Is this possible and, if so, then how can it be done? I run Windows 7 and miktex 2.9 if it's relevant.

Edit, the question above is based on a misunderstanding of how this worked, Khaled cleared that up in the first comment below: What I have done so far (thanks Khaled):

  1. Downloaded the latest luatex from here
  2. Replaced the binary in my miktex folder with the downloaded version (and updated formats and FNDB just in case).
  3. Downloaded the mplib source from here and searched through the file mplibapi.pdf.
  4. Found reference to mp_math_double_mode on page 7.
  5. Looked through luamplib.lua, and inferred that options could be passed in the function

function load()
    local mpx = mplib.new {
        find_file   = finder,
        ini_version = true,
        math_mode = mp_math_double_mode,<--edit here
    }
    mpx:execute(format("input %s ;", currentformat))
    return mpx
end

to which I added the indicated line. Still no luck.

Scott H.
  • 11,047
  • 2
    Luamplib calls the MataPost library embedded in LuaTeX, so you will need to use a new LuaTeX that has the new MataPost. – خالد حسني Feb 20 '13 at 07:53
  • @KhaledHosny Thanks Khaled, that definitely answers part of my question. If I use a newer luatex, is the higher precision enabled by default? – Scott H. Feb 20 '13 at 18:56
  • I don’t think so, the default will be the same as the standalone MetaPost, but you can set numbersystem from MetaPost code (the command line option changed to --numbersystem as well). – خالد حسني Feb 20 '13 at 20:20
  • So within \begin{mplibcode} and \end{mplibcode} I can use numbersystem=double; and that should work? – Scott H. Feb 20 '13 at 20:24
  • I think so, but note that I know near nothing about MetaPost, this is what I gather from reading MetaPost release note. – خالد حسني Feb 20 '13 at 23:37
  • @KhaledHosny Thanks for the info, I've mucked around a bit but can't seem to make it work. – Scott H. Feb 21 '13 at 01:37
  • @Scott H. It wasn't possible until recently to make MetaPost use the double numbersystem from luamplib. Now it's the case since version 2.4 of luamplib (current CTAN version is 2.6). You only have to enter \mplibnumbersystem{double} in the preamble. – Franck Pastor Mar 14 '14 at 12:58
  • @fpast Ah, many thanks. So is my answer below then incorrect? If you'd be inclined to write up a corrected version (or canonical version) then I'd be happy to accept it. – Scott H. Mar 14 '14 at 19:28
  • @Scott H. Well, honestly, I can't say if it is correct or not, I haven't checked and anyway I don't know much of Lua yet. What I meant to say is that the use of MetaPost's double number system is now accessible with luamplib without having to tweak luamplib's code. The necessary work has been done by the current (and quite active) maintainer, Dohyun Kim. Please look at this discussion (in which this very thread is mentioned ;-), which started it all: https://github.com/lualatex/luamplib/issues/21 – Franck Pastor Mar 14 '14 at 20:17
  • To add some references: It is usually a bad idea to change packages and binaries in the main MiKTeX installation path. See Purpose of local texmf trees and Create a local texmf tree in MiKTeX. – Speravir Mar 15 '14 at 01:01

2 Answers2

6

The problem is not with the command above (i.e. one of the commented lines in the code below should work) but rather that MikTex runs an older version of the luatex binary (beta-0.70...) that cannot be updated by simply replacing the binary.

function load()
    local mpx = mplib.new {
        find_file   = finder,
        ini_version = true,
        --math_mode = 1,
        --math_mode = double,
        --math_mode = mp_math_mode_double,
    }
    mpx:execute(format("input %s ;", currentformat))
    return mpx
end
Scott H.
  • 11,047
5

As I said in a comment, with the current CTAN version of luamplibit is no longer necessary to look into luamplib's code to have access to the "double" "numbersystem" option (it is not called "math" anymore). Here I give a concrete example:

\documentclass{article}
\usepackage{luamplib}
% Allow the list of MP pictures below to be moved horizontally 
% via LaTeX commands and environments
\everymplib{verbatimtex \leavevmode etex; beginfig(0);} 
\everyendmplib{endfig; verbatimtex \leavevmode etex;}

\begin{document}

\begin{center}
   \mplibnumbersystem{double}
   \begin{mplibcode}
      draw textext("Double number system: $\sqrt2 =" & decimal sqrt 2 & "$.");
   \end{mplibcode}\\
   \mplibnumbersystem{scaled} % return to default
   \begin{mplibcode}
      draw textext("Scaled number system:  $\sqrt2 =" & decimal sqrt 2 & "$.");
   \end{mplibcode}\\
   \mplibnumbersystem{double}
   \begin{mplibcode}
       draw textext("Big number: $10^9 =" & decimal 1e9 & "$.");
   \end{mplibcode}
\end{center}

\end{document}

Result:

enter image description here

See luamplib's documentation for more details.

Edit : I've added an example showing the acceptance of scientific notation by MetaPost when numbersystem is set to double.

Franck Pastor
  • 18,756