2

I know this is a question that possibly does not belong to pure TeX, as MetaFont is part of a project to which TeX relates, ie as part of building TeX. My question is as follows: I call MetaFont from my bash terminal. and then provide the expr entry (see below).

    #mf
This is METAFONT, Version 2.7182818 (TeX Live 2019/Arch Linux) (preloaded base=mf)
**expr
(/usr/share/texmf-dist/fonts/source/public/knuth-lib/expr.mf
gimme an expr: 4+5-8+4
>> 5
gimme an expr:

Now I wanted, instead of typing an expression, that I could write some command to have metafont read a line from a values.txt (see below) file containing the expression 4+5-8+4 in the first line e etc.

values.txt:

4+5-8+4
4+5-8+7
4+5-8+13

My output should be:

5
11
17

Is there any way to do this?

  • 1
    you could use the commandline mf expr < values.txt but why use expr which is just an infinite loop reading standard in, rather than have a normal metafont file as input? – David Carlisle Jan 7 at 18:24
  • @DavidCarlisle ThankXD! I am trying to use metafont within a python subprocess module to automatically read multiple lines as in values.txt, perform the operations, and direct each result of each line separately to a result.txt file containing each result separated by line respectively with respect to values.txt . I will try from now on to draw inspiration from your advice. – Diego Bnei Noah Jan 7 at 18:35
  • @DavidCarlisle Your suggestion solves the whole question but should I close this question? – Diego Bnei Noah Jan 7 at 18:49
  • 1
    I may as well post an answer, we don't get many metafont questions, and egreg is always happy to see me pick up a few points:-) – David Carlisle Jan 7 at 18:50
  • @DavidCarlisle I understand :-) kkkk. In the meantime I need to figure out how to write output to a file without printing all the extra commands that are shown. – Diego Bnei Noah Jan 7 at 18:53
3

You can use your shell facilities to take standard in and standard out from files, so

 mf expr < values.txt  > results.txt

would put the results in results.txt:

This is METAFONT, Version 2.7182818 (TeX Live 2019) (preloaded base=mf)
(/usr/local/texlive/2019/texmf-dist/fonts/source/public/knuth-lib/expr.mf
gimme an expr: >> 5
gimme an expr: >> 8
gimme an expr: >> 14
gimme an expr: 
! Emergency stop.
...
  • Thanks now I need to send to an output file only the results. I did mf expr < values.txt > results.txt, but the result.txt file ended up containing all terminal output instead of just the results of operations. I will try this with regex or some functionality in python. Not sure what to limit what should be sent to – Diego Bnei Noah Jan 7 at 18:57
  • 1
    @DiegoBneiNoah expr.mf seems to be only 5 lines and is as I say an iinfinite loop so it only ends if you get an error, I'm sure you could write a similar file that output more carefully and accepted some specific term to stop cleanly. – David Carlisle Jan 7 at 19:00
  • As I understand it if I modify one of these lines string s[]; s1="abra"; path p[]; p1=(0,0)..(3,3); p2=(0,0)..(3,3)..cycle; tracingonline:=1; scrollmode; forever: message "gimme an expr: "; s0:=readstring; show scantokens s0; endfor. What kind of programming language is this? MetaPost? – Diego Bnei Noah Jan 7 at 19:44
  • 1
    @DiegoBneiNoah it's metafont (I assumed you knew that to start with???) metapost is a later system derived from metafont. But metafont is a font design language, what are you using it for if not designing fonts? – David Carlisle Jan 7 at 20:06
  • 1
    using metafont for math from python seems a very bizarre choice, but it's a free world:-) – David Carlisle Jan 7 at 20:20

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.