2

In MetaPost I label something with:

Label(1)(percent, ", 269 GiB") (inwards, 0) withcolor (1, 1, 0) ;

Unfortionately the space after the comma and the space between 269 and GiB is represented by a hyphen like symbol in the output.

How to obtain a real space?

prologues := 3 ; 
input piechartmp; 

beginfig(1) ; 
  SetupColors((0.7, 0.7), this, this) ; 
  SetupPercent(this, "%") ; 
  Segment(64, "acc") ; 
  Segment(24, "bak") ; 
  Segment(12, "ext") ; 
  SegmentState(3, this, 0.3) ; 
  PieChart(2cm, 0.15, 60, 0,0) ; 
  Label.auto(0) (name) (outwards, 0) ; 
  Label(1)(percent, ", 269 GiB") (inwards, 0) withcolor (1, 1, 0) ; 
  Label(2)(percent, ", 100 GiB") (inwards, 0) withcolor (1, 1, 0) ;
  Label(3)(percent, ", 48 GiB") (inwards, 0) withcolor (1, 1, 0) ;
  pickup pencircle scaled 2pt ; 
endfig ; 

end.

Sample output

1

3 Answers 3

3

The trouble is that when Metapost converts a string into a picture, it just does it in the simplest possible way, turning each ascii code in the string to the appropriate glyph (also using the font metric, I guess). With a TeX font, the space character (ASCII 32) is not needed for typesetting, so it is used for a funny little diagonal dash thing, which you'll see when Metapost does its thing.

The simplest solution is to have Metapost ask TeX to typeset your label by replacing "269 GiB" with btex 269 GiB etex, or by using the TEX() command from the TEX.mp file.

Update: I noted the comments below that this doesn't work with the metapost package piechartmp.mp. This is because btex ... etex generates a picture whereas the Label command expects a string. I wasn't familiar with this package, and assumed the command to be more like the plain metapost command label which is happy with text, pictures, etc.

I had a look in the file piechartmp.mp and there are several layers of macros that build up a string and then pass it to the command _makeText, which is defined on lines 864-886:

vardef _makeText primary s =
    if ( pc_sTextScheme > 0 ) :
        write "verbatimtex" to pc_TeXFile ;
        if ( pc_sTextScheme = 3 ):
            write "%&latex" to pc_TeXFile ;
        else:
            write pc_sTeXFormat to pc_TeXFile ;
        fi;
        if ( pc_sTextScheme > 1 ):
            write "\documentclass{minimal}" to pc_TeXFile ;
            write pc_sTeXSettings to pc_TeXFile ;
            write "\begin{document}" to pc_TeXFile ;
        else:
            write pc_sTeXSettings to pc_TeXFile ;
        fi;
        write "etex" to pc_TeXFile ;
        write "btex "&s&" etex" to pc_TeXFile;
        write EOF to pc_TeXFile;
        scantokens ("input " & pc_TeXFile )
    else:
        s infont defaultfont scaled defaultscale
    fi
enddef;

You can see from this that if sTextScheme > 1 then a small metapost file will be created that includes btex ... etex delimiters, and this is then read back in. (Incidentally, this is what TEX() does.)

So the author of this package has implemented this functionality - we just need to find out how to use it! On line 1016 the command SetupText sets it.

On page 17 of the documentation of the piechartmp.mp package it tells you that the command SetupText is used to control typesetting of labels. I tried to get it to work on your example file, but couldn't make it work.

So my answer is almost complete, except for the "W" of "MWE".

Update 2: I have just seen that Franck Pastor actually found some documentation telling us how he got it to work.

5
  • prologues:=3; input piechartmp; beginfig(1); SetupColors((0.7, 0.7),this,this); SetupPercent(this,"%"); Segment(64,"acc"); Segment(24,"bak") ; Segment(12, "ext"); SegmentState(3,this,0.3); PieChart(2cm,0.15, 60, 0,0); picture size[]; size1=btex 269 GiB etex; size2=btex 100 GiB etex; size3=btex 48 GiB etex; Label.auto(0) (name) (outwards, 0); Label(1)(percent, size1) (inwards, 0) withcolor (1, 1, 0); Label(2)(percent, size2) (inwards, 0) withcolor (1, 1, 0); Label(3)(percent, size3) (inwards, 0) withcolor (1, 1, 0); pickup pencircle scaled 2pt; endfig ; end. Nov 26, 2015 at 5:18
  • It goes wrong here: Label(1)(percent, size1) (inwards, 0) withcolor (1, 1, 0); Nov 26, 2015 at 5:31
  • @FranckyLeyn You should edit this information into your question. Nov 26, 2015 at 7:24
  • @AndrewKepert Unfortunately, using btex…etex can't work here. The Label command of piechartmp accepts only string arguments. Nov 26, 2015 at 10:23
  • MP can use any of the fonts in psfonts.map (or any that you add locally). Many of these have excellent and useful font encodings -- the business with the obscure diagonal dash is just because cmr10 is the default font.
    – Thruston
    Nov 26, 2015 at 11:03
2

According to the LaTeX Graphics Companion (Second edition) itself, p. 174 and 175, you should insert a line like the following:

SetupText(1, "", "");

This one tells PieChartMP to use TeX as typesetting engine and so solves the problem explained above by Andrew Kepert: the space string character is now appropriately handled by TeX. See the LGC2 for further information about the other options, particularly with the use of LaTeX.

Also, replace

SetupPercent(this, " %") ;

by

SetupPercent(this, " \%") ;

The following program should work with your installation as it does with mine:

prologues := 3;
input piechartmp; 

beginfig(1) ; 
  SetupColors((0.7, 0.7), this, this) ; 
  SetupText(1, "", "");
  SetupPercent(this, " \%") ; 
  Segment(64, "acc") ; 
  Segment(24, "bak") ; 
  Segment(12, "ext") ; 
  SegmentState(3, this, 0.3) ; 
  PieChart(2cm, 0.15, 60, 0,0) ; 
  Label.auto(0) (name) (outwards, 0) ; 
  Label(1)(percent, ", 269 GiB") (inwards, 0) withcolor (1, 1, 0) ; 
  Label(2)(percent, ", 100 GiB") (inwards, 0) withcolor (1, 1, 0) ;
  Label(3)(percent, ", 48 GiB") (inwards, 0) withcolor (1, 1, 0) ;
  pickup pencircle scaled 2pt ; 
endfig ; 

end.

enter image description here

2

The actual problem here is that the default font used by Metapost is cmr10 which has the plain TeX textfont0 encoding; since this does not have a space at code point 32 this is a particularly poor choice!

You can fix this by changing the default font to one that has a more useful encoding. Try adding this at the top of your file:

defaultfont := "phvr8r";

This will set all the text in Helvetica using the "8r" encoding (which is very similar to ISO Latin 1 and Windows 1252).

If you want to stick with "Computer Modern" then use this:

defaultfont := "texnansi-lmr10";

This uses "Latin Modern" (which looks the same as "Computer Modern") with the "TeX and ANSI" encoding, which again is quite similar to ISO Latin 1.

For more fonts available to Metapost, look in your local psfonts.map file.

The next problem you will have is that the labels no longer fit on your pie slices, so you will want to scale the font down a bit. You can do this by setting the default font scale. Here is your output with the following two lines added at the top:

defaultfont := "phvr8r";
defaultscale := 0.5;

Some pie

9
  • I want 3 additional things: Nov 28, 2015 at 18:00
  • I want 3 additional things: 1) I want the "=" sign or "," sign to be replaced y something like the (La)TeX $\equiv$ sign., 2) In the LaTeX Graphics companion, secobd edition on p. 174 above there is given an example of a oie slice that is lowered. I don't understand why this isn't working for me. 3) I want a title like "100% $\equiv$ 402 GiB". Nov 28, 2015 at 18:07
  • See my answer to your original question about this.
    – Thruston
    Nov 28, 2015 at 18:59
  • You don't answer my questions. The title issue and the \equiv sign are new. I'm also wondering why the lowered pie slice is present in the LaTeX Graphics Companion and not in my similar case. Nov 29, 2015 at 14:28
  • I thought I had addressed those points in my answer to your original question. I answered them there because this question was specifically about the space character in MP which is more general than your detailed questions about piechartmp. If you don't like my answers, then may be you could work it out for yourself from the manual, and post your own answer.
    – Thruston
    Nov 29, 2015 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .