The wiki claims setting up an MPenvironment is enough to change the font in MetaPost graphics: \startMPenvironment%[global] \switchtobodyfont [sans] \stopMPenvironment \starttext This should be serif. \startMPcode draw textext("This should be in sans."); \stopMPcode \stoptext However, this has no effect. All text is in default serif font. If [global] is provided, all text is in sans font. I am aware of a similar issue in a thread last year¹, but the solution didn't really address the problem. textext("\sans This should be sans.") works here, but the point is that the MPenvironment fails. Why is that? Marco [1] http://thread.gmane.org/gmane.comp.tex.context/69044
On Thu, 3 May 2012, Marco wrote:
The wiki claims setting up an MPenvironment is enough to change the font in MetaPost graphics:
\startMPenvironment%[global] \switchtobodyfont [sans] \stopMPenvironment
\starttext This should be serif.
\startMPcode draw textext("This should be in sans."); \stopMPcode \stoptext
However, this has no effect. All text is in default serif font. If [global] is provided, all text is in sans font. I am aware of a similar issue in a thread last year¹, but the solution didn't really address the problem. textext("\sans This should be sans.") works here, but the point is that the MPenvironment fails. Why is that?
Metapost now runs as a library. All the text is first typeset by ConTeXt and metapost only knows the bounding box of the labels. You can try (untested): \starttext This is serif \switchtobodyfont[sans] \startMPcode draw textext("This should be sans"); \stopMPcode \stoptext Aditya
On 2012-05-02 Aditya Mahajan
Metapost now runs as a library. All the text is first typeset by ConTeXt and metapost only knows the bounding box of the labels.
You can try (untested):
\starttext
This is serif
\switchtobodyfont[sans] \startMPcode draw textext("This should be sans"); \stopMPcode
\stoptext
This works, of course. However it continues with sans font even after \stopMPcode. This is better (but clumsy): \start \switchtobodyfont[sans] \startMPcode draw textext("This should be sans"); \stopMPcode \stop Here serif again. The text in Metapost adapts to the text set in ConTeXt. But the font setup should *only* be set for MetaPost, not regular text. Does that mean, that MPenvironment is deprecated and does not work at all? Marco
On Thu, May 3, 2012 at 3:13 AM, Marco wrote:
The text in Metapost adapts to the text set in ConTeXt. But the font setup should *only* be set for MetaPost, not regular text.
Does that mean, that MPenvironment is deprecated and does not work at all?
Please don't rely on my answer since I haven't been following the development as closely as I used to in past. But my guess is that the argument goes into the opposite way. I past (and still in MKII) one *had to* set up fonts twice - once for the main document and once for MetaPost since MetaPost did its own processing of labels and MetaPost didn't see the ConTeXt font setups. So it was "difficult" to convince MetaPost to use the same font. Now (as Aditya explained) metapost automatically inherits font setups from the main document and it might be that nobody ever thought of / requested / needed to have a special setup for using different font for MetaPost labels. I can think of many workarounds to this, but I agree that there is a valid reason why \startMPenvironment (or some other command) should be able to change the font inside metapost labels only. Mojca
On Fri, 4 May 2012, Mojca Miklavec wrote:
I can think of many workarounds to this, but I agree that there is a valid reason why \startMPenvironment (or some other command) should be able to change the font inside metapost labels only.
A better alternative would to define \setupMPtext [ style=..., color=..., setups=..., ] that can be used to set the style for metapost text. Aditya
On 2012-05-04 Aditya Mahajan
On Fri, 4 May 2012, Mojca Miklavec wrote:
But my guess is that the argument goes into the opposite way. I past (and still in MKII) one *had to* set up fonts twice - once for the main document and once for MetaPost since MetaPost did its own processing of labels and MetaPost didn't see the ConTeXt font setups. So it was "difficult" to convince MetaPost to use the same font.
I agree, it's a big step forward towards usability and consistency to have MetaPost automatically inherit ConTeXts settings. However, it went out-of-control now.
A better alternative would to define
\setupMPtext [ style=..., color=..., setups=..., ]
that can be used to set the style for metapost text.
+1 Marco
On 4-5-2012 13:09, Marco wrote:
On 2012-05-04 Aditya Mahajan
wrote: On Fri, 4 May 2012, Mojca Miklavec wrote:
But my guess is that the argument goes into the opposite way. I past (and still in MKII) one *had to* set up fonts twice - once for the main document and once for MetaPost since MetaPost did its own processing of labels and MetaPost didn't see the ConTeXt font setups. So it was "difficult" to convince MetaPost to use the same font.
I agree, it's a big step forward towards usability and consistency to have MetaPost automatically inherit ConTeXts settings. However, it went out-of-control now.
well, you still get text and not something random, so out-of-control is a bit too strong anyhow, we can do \newconditional\MPLIBtextgetdone \def\MPLIBsettext#1% #2% {\ifconditional\MPLIBtextgetdone \else \cldcontext{metapost.tex.get()}% \settrue\MPLIBtextgetdone % no \global needed \fi \dowithnextbox{\ctxlua{metapost.settext(\number\nextbox,#1)}}\hbox} \def\MPLIBresettexts {\ctxlua{metapost.resettextexts()}%$ \setfalse\MPLIBtextgetdone} \starttext Serif \startMPcode draw textext("\ss Sans") ; \stopMPcode Serif \startMPenvironment \ss \stopMPenvironment \startMPcode draw textext("Sans") ; \stopMPcode Serif \stoptext
A better alternative would to define
\setupMPtext [ style=..., color=..., setups=..., ]
that can be used to set the style for metapost text.
this is ok for me, but then we mighe as well drop \startMPenviroment (and someone has to wikify that then) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 4-5-2012 09:13, Aditya Mahajan wrote:
On Fri, 4 May 2012, Mojca Miklavec wrote:
I can think of many workarounds to this, but I agree that there is a valid reason why \startMPenvironment (or some other command) should be able to change the font inside metapost labels only.
A better alternative would to define
\setupMPtext [ style=..., color=..., setups=..., ]
that can be used to set the style for metapost text.
As we already have instances, I've extended that mechanism, so one can say: \startsetups mp:instance:one indeed:\space \stopsetups \setupMPinstance [metafun] [textstyle=bold, textcolor=darkgreen, setups=mp:instance:one] \defineMPinstance [mympinstance] [metafun] [textcolor=red] \starttext \startMPcode draw textext("some text") ; \stopMPcode \startMPcode{mympinstance} draw textext("some text") ; \stopMPcode \stoptext
+1
Marco
So .. we know who is going to wikify this ... Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2012-05-05 Hans Hagen
On 8-5-2012 19:01, Marco wrote:
On 2012-05-05 Hans Hagen
wrote:
Did I?
This code fails:
\defineMPinstance [mympinstance] [metafun] [textcolor=red]
\starttext
\startMPcode draw textext("some text") ; \stopMPcode
\startMPcode{mympinstance} draw textext("some text") ; \stopMPcode
\stoptext
Marco
It works here. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2012-05-08 Hans Hagen
On 8-5-2012 19:01, Marco wrote:
On 2012-05-05 Hans Hagen
wrote: Did I?
My bad ;)
This code fails:
\defineMPinstance [mympinstance] [metafun] [textcolor=red]
\starttext
\startMPcode draw textext("some text") ; \stopMPcode
\startMPcode{mympinstance} draw textext("some text") ; \stopMPcode
\stoptext
Marco
It works here.
Fails here, source and log are attached. current version: 2012.05.08 13:45 Marco
On 8-5-2012 19:19, Marco wrote:
On 2012-05-08 Hans Hagen
wrote: On 8-5-2012 19:01, Marco wrote:
On 2012-05-05 Hans Hagen
wrote: Did I?
My bad ;)
This code fails:
\defineMPinstance [mympinstance] [metafun] [textcolor=red]
\starttext
\startMPcode draw textext("some text") ; \stopMPcode
\startMPcode{mympinstance} draw textext("some text") ; \stopMPcode
\stoptext
Marco
It works here.
Fails here, source and log are attached.
ok, can you add this to cont-new.mkiv (after \unprotect): \def\m_meta_colo_initializations{% vardef OverlayLineColor=\MPcolor{\overlaylinecolor} enddef; vardef OverlayColor=\MPcolor{\overlaycolor} enddef; } I have that in my local experimental code. It has to do with the fact that mp's color spaces are not compatible with each other. As I've used that patch for quite a while now I could probably move it to the core. Maybe more users can test this. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2012-05-08 Hans Hagen
ok, can you add this to cont-new.mkiv (after \unprotect):
\def\m_meta_colo_initializations{% vardef OverlayLineColor=\MPcolor{\overlaylinecolor} enddef; vardef OverlayColor=\MPcolor{\overlaycolor} enddef; }
That works.
As I've used that patch for quite a while now I could probably move it to the core.
Since you use it for a while it seems to work ⇒ into the core Thanks a lot Hans for implementing this. Wikified: http://wiki.contextgarden.net/Command/defineMPinstance http://wiki.contextgarden.net/Command/setupMPinstance Best wishes Marco
Hello,
many thanks Marco for wikifying.
On Tue, 08 May 2012 21:57:04 +0200, Marco
Thanks a lot Hans for implementing this.
Wikified:
http://wiki.contextgarden.net/Command/defineMPinstance http://wiki.contextgarden.net/Command/setupMPinstance
Best wishes
Marco
With the permission, I tried to replace the tag <texcode> with <context> to get source and result. <context mode="mkiv" source="yes" text="Gives:"> ... </context> Unfortunately, the result doesn't appear. So, what to do to make the example work? Will it work automatically once the Ctx/MP engine updates on wiki? Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
On 2012-05-10 Procházka Lukáš Ing. - Pontex s. r. o.
With the permission, I tried to replace the tag <texcode> with <context> to get source and result.
<context mode="mkiv" source="yes" text="Gives:"> ... </context>
Unfortunately, the result doesn't appear.
The code is MkIV only and the wiki uses MkII.
So, what to do to make the example work?
Find someone who has time to implement and administrate a working MkIV wiki solution.
Will it work automatically once the Ctx/MP engine updates on wiki?
*If* the engine gets updated someday, it will probably work, yes. Marco
participants (5)
-
Aditya Mahajan
-
Hans Hagen
-
Marco
-
Mojca Miklavec
-
Procházka Lukáš Ing. - Pontex s. r. o.