Difference between revisions of "Math/fractions"

From Wiki
Jump to navigation Jump to search
Line 10: Line 10:
 
\stopbuffer
 
\stopbuffer
  
\framed[frame=off,align=normal]{%  <=== for this wiki
+
\framed[frame=off,align=normal]{%  <=== just to improve wiki rendering
 
Each time, we display consecutively: math style, display style, script style, and text style.
 
Each time, we display consecutively: math style, display style, script style, and text style.
  

Revision as of 17:03, 12 May 2024

Fractions

\frac switches the math style while \tfrac (textstyle), \dfrac (displaystyle) and \sfrac (scriptstyle) enforce a certain style.


\startbuffer[frac]
\frac{1}{2} + \dfrac{1}{2} - \sfrac{1}{2} + \tfrac{1}{2}
\stopbuffer

\framed[frame=off,align=normal]{%   <=== just to improve wiki rendering
Each time, we display consecutively: math style, display style, script style, and text style.

With \tex{startformula} (display mode)
\startformula
\getbuffer[frac]
\stopformula

With \tex{m} (inline mode): \m{\getbuffer[frac]}

With \tex{startformula} (display mode)
\startformula
  \frac
    {\getbuffer[frac]}
    {\getbuffer[frac]}
\stopformula

With \tex{m} (inline mode): 
\m{\frac
  {\getbuffer[frac]}
  {\getbuffer[frac]}}

}

Binomial coefficients

To write binomial coefficients you use any of \binom, \tbinom or \dbinom (the latter two if you want to force text style or display style respectively). These commands are defined as fractions in ConTeXt, and can be set up with \setupmathfractions.

The default look of the binomial coefficients look good in several fonts, but for example not perfect in Latin Modern. You can play with \setupmathfractions, and in particular, you can try

\setupmathfractions[binomial][
fences=parenthesis,
%threshold=1.5,
]

Below we show some of the often used fonts, together with the default setting and the one just suggested. You can also play with the threshold key.

\setuphead[chapter][align=middle]
\setuphead[section][style=\bfa]
\setuphead[subsection][style=\it]


\setuplayout[
topspace=1in,
bottomspace=1in,
header=0pt,
footer=0pt,
backspace=1in,
margin=0pt,
width=fit,
height=fit,
]

\startbuffer
\type{\binom{n}{k}}: $\binom{n}{k}$\par
\type{\tbinom{n}{k}}: $\tbinom{n}{k}$\par
\type{\dbinom{n}{k}}: $\dbinom{n}{k}$\par
\stopbuffer

\starttext

\title{Binomial coefficients}

\startcolumns[n=2]

\subject{Default settings}

\subsubject{Latin Modern}
\getbuffer

\switchtobodyfont[pagella]
\subsubject{Pagella}
\getbuffer

\switchtobodyfont[stixtwo]
\subsubject{STIX Two}
\getbuffer

\switchtobodyfont[lucidaot]
\subsubject{Lucida}
\getbuffer

\column[yes]

\setupmathfractions[binom][
fences=parenthesis,
]

\switchtobodyfont[modern]
\subject{With fences=parenthesis}
\subsubject{Latin Modern}
\getbuffer

\switchtobodyfont[pagella]
\subsubject{Pagella}
\getbuffer

\switchtobodyfont[stixtwo]
\subsubject{STIX Two}
\getbuffer

\switchtobodyfont[lucidaot]
\subsubject{Lucida}
\getbuffer

\stopcolumns
\stoptext

The result of the code above, with the standalone from 2017-09-05 is given below.

binomialcoefficients.png