Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
Luamplib calls the MataPost library embedded in LuaTeX, so you will need to use a new LuaTeX that has the new MataPost. –  Khaled Hosny Feb 20 '13 at 7: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). –  Khaled Hosny 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. –  Khaled Hosny Feb 20 '13 at 23:37

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
Thanks for adding this, and for the link above :) Nice to know this can be done simply! –  Scott H. Mar 16 at 20:13

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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