2

I am trying unsuccessfully to pass fontawesome symbols as variable to MetaFun.

I tried things like, passing the symbol directly through the variable

\usesymbols [fontawesome]


\startuniqueMPgraphic{MPfa}{symbol}
  picture pic ;
  pic := textext.rt(\MPvar{symbol}) ;

  draw pic ;
\stopuniqueMPgraphic


\starttext
  \useMPgraphic{MPfa}{symbol=\symbol[fontawesome-solid][font-awesome]}
\stoptext

Passing only the fontawesome flag

\usesymbols [fontawesome]


\startuniqueMPgraphic{MPfa}{symbol}
  picture pic ;
  pic := textext.rt(\symbol[fontawesome-solid][\MPvar{symbol}]) ;

  draw pic ;
\stopuniqueMPgraphic


\starttext
  \useMPgraphic{MPfa}{symbol=font-awesome}
\stoptext

Using MPtext and MPString both with MPvar

\usesymbols [fontawesome]


\setMPtext{fa}{\symbol[fontawesome-solid][font-awesome]}


\startuniqueMPgraphic{MPfa}{symbol}
  picture pic ;
  pic := textext.rt(\MPString{\MPvar{symbol}}) ;

  draw pic ;
\stopuniqueMPgraphic


\starttext
  \useMPgraphic{MPfa}{symbol=fa}
\stoptext

and without MPvar

\usesymbols [fontawesome]


\setMPtext{fa}{\symbol[fontawesome-solid][font-awesome]}


\startuniqueMPgraphic{MPfa}{symbol}
  picture pic ;
  pic := textext.rt(\MPString{symbol}) ;

  draw pic ;
\stopuniqueMPgraphic


\starttext
  \useMPgraphic{MPfa}{symbol=fa}
\stoptext

However nothing seems to compile. What did I miss ?

4
  • What do you want, exactly. If you consider a workaround, you can try the following: \usesymbols [fontawesome] \startuseMPgraphic{MPfa} picture p; p := thelabel.rt("\MPtext{fasymbol}", origin); draw p; \stopuseMPgraphic \def\fampsym#1{\setMPtext{fasymbol}{\symbol[fontawesome][#1]}\useMPgraphic{MPfa}} \starttext \fampsym{check} \fampsym{globe} \stoptext
    – user193767
    May 10, 2020 at 14:28
  • In p. 143 of Metafun manual some commands for TeX content are provided: pragma-ade.com/general/manuals/metafun-p.pdf
    – user193767
    May 10, 2020 at 14:34
  • Could you elaborate on how you intend to use this. Depending on that, there may be simpler solutions.
    – Aditya
    May 29, 2020 at 17:21
  • Well, I came to a better solution by cutting down what I wanted in simpler pieces. Ultimately I used overlays. There probably is a much better solution but at my level of ConTeXt-fu I can't see it.
    – user213111
    May 29, 2020 at 18:28

2 Answers 2

1

I know this is a late answer, but the following trick may be helpful to other ConTeXt users: prefixing s:: to your variable name and using \MPvariable instead of \MPvar let you pass strings:

\usesymbols[fontawesome]

\startuniqueMPgraphic{MPfa}{s::symbol}
  picture pic ;
  pic := textext.rt("\symbol[fontawesome][\MPvariable{symbol}]") ;
  draw pic;% scaled 10; %for dramatic effects
\stopuniqueMPgraphic

\startTEXpage
\useMPgraphic{MPfa}{symbol=bell}
\stopTEXpage

enter image description here

2

None of your examples work because ConTeXt allows only a few certain argument types for the \useMPgraphic etc. commands.

Only the following three argument type for a key are possible:

  1. The name of a color,
  2. a number or
  3. a valid dimension.

In your example you never pass a valid argument to the symbol key which result in the error message.

2
  • So there is no better way than in @JairoADelRio answer ?
    – user213111
    May 10, 2020 at 15:35
  • There are different methods to implement it (e.g. using \setvariables to pass the values) it's the way you should go. May 10, 2020 at 15:54

You must log in to answer this question.