4

How can I make all labels in my circuit monospaced? I found this: Can I change all math output to use monospaced text? but this also affects my equations outside figures.


    \documentclass{minimal}
    \usepackage{pst-circ}
    \usepackage{amsmath}
    \everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}
    \usepackage[utf8]{inputenc}
    \begin{document}
    \setbox0\hbox{$ $}
        \begin{pspicture}(5,2)
        \psset{linewidth=1pt}
        \pnode(0,1){A}
        \pnode(3,1){B}
        \pnode(5,1){C}
        \newdiode(A)(B){$D_1$}
        \resistor(B)(C){$R_1$}
        \end{pspicture}
    $ \frac{1}{2\sqrt{x}} $
    \end{document}
Can I redefine pst-circ label command to use monospaced font?
user15941
  • 307
  • What about just using $\mathtt{D_1}$ and $\mathtt{R_1}$? – Werner Jun 02 '13 at 06:21
  • The final circuits are far more complicated and there is an exact solution for sans serif fonts: http://tex.stackexchange.com/questions/26145/change-math-font-for-figures-only-including-tikz-environments-within-figures however I can't merge two mentioned methods to work together. – user15941 Jun 02 '13 at 09:47

2 Answers2

3

You're using the wrong order; first you have to set \everymath and then set a box to initialize the mechanism. If you set \everymath inside the pspicture, the effect will vanish with its end.

\documentclass{standalone}
\usepackage{pst-circ}
\usepackage{amsmath}

\usepackage[utf8]{inputenc}
\begin{document}
\begin{pspicture}(5,2)
\everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}
\sbox0{$$}% initialize tt for all math formulas
\psset{linewidth=1pt}
\pnode(0,1){A}
\pnode(3,1){B}
\pnode(5,1){C}
\newdiode(A)(B){$D_1$}
\resistor(B)(C){$R_1$}
\end{pspicture}
$\frac{1}{2\sqrt{x}}$
\end{document}

enter image description here

Note that using the minimal class is not recommended for making examples; use article or standalone.


You can define a handier command to get this:

\documentclass{standalone}
\usepackage{pst-circ}
\usepackage{amsmath}

\newcommand{\ttmath}{%
  \everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}%
  \sbox0{$$}% initialize tt for all math formulas
}

\usepackage[utf8]{inputenc}
\begin{document}
\begin{pspicture}(5,2)
\ttmath
\psset{linewidth=1pt}
\pnode(0,1){A}
\pnode(3,1){B}
\pnode(5,1){C}
\newdiode(A)(B){$D_1$}
\resistor(B)(C){$R_1$}
\end{pspicture}
$\frac{1}{2\sqrt{x}}$
\end{document}
egreg
  • 1,121,712
1

try the latest version of pst-circ.tex from http://texnik.dante.de/tex/generic/pst-circ/. It knows two additional arguments:

\documentclass{article}
\usepackage{pst-circ}
\begin{document}
\psset{mathlabel,labelstyle=\tt} %%%%
  \begin{pspicture}(5,2)
    \psset{linewidth=1pt}
    \pnode(0,1){A}
    \pnode(3,1){B}
    \pnode(5,1){C}
    \newdiode(A)(B){D_1}%% without $..$
    \resistor(B)(C){R_1}
    \end{pspicture}
    $ \frac{1}{2\sqrt{x}} $
\end{document}

enter image description here