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 am trying to create an electrical phase symbol in ConTeXt like that produced by the \phase{} command from LaTeX's steinmetz package.

Here is what the symbol looks like:

Is there something out there already or do I need to brew my own? If I do, suggestions would be appreciated. I'm relatively new to ConTeXt and MetaPost.

Here is the meat from the steinmetz package, for reference.

\RequirePackage{pict2e}[2004/07/06]
\newsavebox{\stm@phasebox}
\newlength{\stm@phasedp}
\newlength{\stm@phaseht}
\newlength{\stm@phasetot}
\newlength{\stm@phasewd}
\newcommand\phase[2][1]{%
 \sbox\stm@phasebox{$\ifcase#1\relax\displaystyle\or\textstyle\or\scriptstyle\or\scriptscriptstyle\fi#2$}
\stm@phaseht=\ht\stm@phasebox
\stm@phasedp=\dp\stm@phasebox
\stm@phasetot=\stm@phasedp \advance\stm@phasetot .35ex \advance\stm@phasetot\stm@phaseht
\stm@phasewd=\wd\stm@phasebox \advance\stm@phasewd .5\stm@phasetot
\setbox\stm@phasebox=\vbox to\stm@phaseht{
  \hbox{\setlength{\unitlength}{1pt}\linethickness{.6pt}%
        \edef\ph@x{\strip@pt\stm@phasewd}\edef\ph@y{\strip@pt\stm@phasetot}%
        \dimen@ .5\stm@phasetot \edef\ph@dx{\strip@pt\dimen@}%
\begin{picture}(\ph@x,\ph@y)
 \put(0,0){\circle*{.4}}
 \put(0,0){\line(1,0){\ph@x}}\put(0,0){\line(1,2){\ph@dx}}
 \put(\ph@dx,1.5){\raise\stm@phasedp\vbox{\box\stm@phasebox}}
\end{picture}%
}\vss}%
\advance\stm@phasedp .35ex \advance\stm@phasedp .6pt
\dp\z@=\stm@phasedp \box\stm@phasebox}
share|improve this question
    
Welcome to TeX.sx! –  Torbjørn T. Mar 5 '13 at 19:08
    
In the documentation for MakeCirc, there appears to be a command \modarg which looks like it could be used for this. Unfortunately I couldn't get the package to work, so I cannot confirm it. –  morbusg Mar 8 '13 at 6:43
add comment

1 Answer

The following gives something like usable results:

\startuseMPgraphic{formula}
  picture p;
  pair zu, zl;
  numeric delta, width;
  path roof;
  width = 2.5 pt;
  p := \MPbetex{txt};
  zl := llcorner (p); zu := ulcorner (p);
  delta := ypart(zu) - ypart(zl);
  roof := zu -- zl + (-delta - width, -width) -- lrcorner (p) + (0, -width);
  pickup pencircle scaled 0.7pt;
  draw roof withcolor black;
  draw p withcolor black;
\stopuseMPgraphic


\def\putfm#1{
  \setMPtext{txt}{$ #1 $}
  \hbox{\lower 4pt \hbox{\useMPgraphic{formula}}}
}

\starttext

\section{Vertical}
\putfm {1+2+3+4}

\section{Inline}
Lorem ipsum dolor sit amet, consectetuer \putfm {1-2-3-4-5} adipiscing
elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae,
felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique \putfm {\{a,b\}} senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras
viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices.  Phasellus eu tellus sit amet tortor gravida
placerat. Integer sapien est, iaculis in, pretium quis, viverra ac,
\putfm {1+2+3+4+5} nunc. Praesent eget sem vel leo ultrices
bibendum. Aenean faucibus.  Morbi dolor nulla, malesuada eu, pulvinar
at, mollis ac, nulla.  Curabitur auctor semper nulla. Donec varius
orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis
quis, diam. Duis \putfm {\Sigma x_i} eget orci sit amet orci dignissim
rutrum.

\stoptext

giving

enter image description here

Issues:

  1. I'm not really familiar with setting Metapost graphics inline, and there is clearly too much horizontal space in the above when the formula is set inline. Using setbounds in Metapost will give control over the resulting bounding box. I didn't fiddle with this, because what you want will depend on how you are putting these formula inline, and perhaps you don't want to do that at all;
  2. The last formula, with the \Sigma, has the Steinmetz line too close to the formula inside.
  3. The last and third-from-last formulae have the wrong baseline, because their formulae inside have a different depth which the code doesn't handle. To handle this requires more complex code, such as setting inside a box register, looking at the depth, and doing a \raise dependent on this value. I can try to fix this if it is important. The Latex steinmetz code you posted seems to do this and this is worth fixing.
share|improve this answer
add comment

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.