# Typing of math sign charts

For typing of quantities of solving mathematical problems I would like to type signs charts (diagrams to visualize the values of expressions). Something like this:

x-5       -    |    -    |    +
x+4       -    |    +    |    +
---------------o---------@------------
+   -4    -    5    +


(@ means full circle). Primarily seeking solutions in ConTeXt, but for inspiration welcome and solutions in Plain or LaTeX. Maybe someone has something similar to what would suit my needs? I do not want to insert a picture, I am rather interested in solutions in a tables.

Thanx Jaroslav

I suggest the macro \sgchart which generates desired table. The usage is:

\sgchart {list of points} {formula: signs, formula: signs, formula: signs etc}


for example

\sgchart {-4, ~5} {x-5: --+, x+4: -++, (x+4)/(x-5): +-+}


If the point value isn't preceded by ~ then it is printed with solid bullet (default) and if the ~ precedes then circle is printed. The number of points and the number of formulas are unlimited.

The macro works in plain TeX (and in LaTeX too, because the basic plain TeX syntax is used in this macro). ConTeXt sets catcode of the & to 12 and this brings a little problem. We need to set this catcode to 4 in the area where the macros are defined. This is the reason why there are two lines with \ecatcode macro here. When these lines are used then the macro works in ConTeXt too.

\newdimen\tcolw \tcolw=2.5em % the column width
\edef\ecatcode{\catcode&=\the\catcode&\relax}\catcode&=4
\omit\sgchartR&\kern.2pt\sgchartS{.5\tcolw}\relax\sgchartE#1,\relax,%
\sgchartS{.5\tcolw}\relax\cr
\noalign{\kern2pt}&\def~{}\kern.5\tcolw\sgchartD#1,\relax,\cr}}}
\def\sgchartA#1:#2,{\cr\ifx,#1,\else $#1$&\sgchartB#2{}\expandafter\sgchartA\fi}
\def\sgchartB#1{\hbox to\tcolw{\hss$#1$\hss}\sgchartC}
\def\sgchartC#1{\ifx,#1,\else
\strut\vrule\kern-.4pt\hbox to\tcolw{\hss$#1$\hss}\expandafter\sgchartC\fi}
\def\sgchartD#1#2,{\ifx\relax#1\else\hbox to\tcolw{\hss$#1#2$\hss}\expandafter\sgchartD\fi}
\def\sgchartE#1#2,{\ifx\relax#1\else
\ifx~#1\sgchartS\tcolw\circ \else\sgchartS\tcolw\bullet\fi \expandafter\sgchartE\fi}
\def\sgchartS#1#2{\hbox to#1{\kern-.2pt\sgchartR \ifx\relax#2\else
\kern-.7pt$#2$\kern-.7pt\sgchartR\fi\kern-.2pt}}
\ecatcode

\sgchart{-4, ~5} {x-5: --+, x+4: -++, (x+4)/(x-5): +-+}

\bye


• Does anybody know why ConTeXt sets catcode of & to 12? This means that it is incompatible with plain TeX. Feb 27, 2015 at 13:56
• My thoughts on why changing the catcode of & is a good idea. Feb 28, 2015 at 17:56
• I asked for it in ConTeXt mailing list. The answer is that context table mechanisms don't use & (and never used it) so there is no reason to make & special. The _ and ^ are also normal characters. For now developers keep the $for math (and in math mode the & ^ _ work as expected). Mar 1, 2015 at 6:30 Is this enough? \documentclass[12pt]{article} \usepackage[english]{babel} \begin{document} \begin{verbatim} x-5 - | - | + x+4 - | + | + ------------0-------@---------- + -4 - 5 + \end{verbatim} \end{document}  If not you could use the (mathematical) array environment. • O,sorry, there should be some linebreakes in the code. Feb 26, 2015 at 14:47 • You have to leave a blank line before the code. If you select the code parts and click the {} icon, the blank line is automatically supplied and the code is properly indented by four spaces (hitting Control-K does the same). Feb 26, 2015 at 14:50 Plain TeX (requires e-TeX, though): \def\crulefill{\leaders\hrule height \dimexpr\fontdimen22\textfont2+0.2pt\relax depth -\dimexpr\fontdimen22\textfont2-0.2pt\relax \hfill } \def\hollow{$\kern-.8pt\circ\kern-.8pt$} \def\filled{$\kern-.8pt\bullet\kern-.8pt\$}

\vbox{\offinterlineskip\tabskip=0pt \halign{% \strut#\hfil\quad& \hfil\qquad#\qquad\hfil& \hfil\vrule#\hfil& \hfil\qquad#\qquad\hfil& \hfil\vrule#\hfil& \hfil\qquad#\qquad\hfil\cr x-5&-&&-&&+\cr x+4&-&&+&&+\cr \multispan{2}\crulefill&\omit\hfil\hollow\hfil& \omit\crulefill&\omit\hfil\filled\hfil&\omit\crulefill\cr &+&\omit\hidewidth-4\hidewidth&-&\omit\hidewidth5\hidewidth&-\cr }}

\bye
`