Difference between revisions of "Math/fractions"

From Wiki
Jump to navigation Jump to search
Line 102: Line 102:
 
\framed[frame=off,align=normal]{%  <=== just to improve wiki rendering
 
\framed[frame=off,align=normal]{%  <=== just to improve wiki rendering
  
\startbuffer
+
\starttabulate[|l|l|]
\starttabulate[|l|l|l|]
 
\HL
 
\NC {\bf Code}          \NC {\bf Typesetting} \NC\NR
 
\HL
 
 
\NC \type{\binom{n}{k}}  \NC $\binom{n}{k}$    \NC\NR
 
\NC \type{\binom{n}{k}}  \NC $\binom{n}{k}$    \NC\NR
 
\NC \type{\tbinom{n}{k}} \NC $\tbinom{n}{k}$  \NC\NR
 
\NC \type{\tbinom{n}{k}} \NC $\tbinom{n}{k}$  \NC\NR
Line 113: Line 109:
 
\stopbuffer
 
\stopbuffer
  
 +
\title{Binomial coefficients}
  
 +
\startcolumns[n=2,separator=rule]
  
\starttabulate[|l|l|l|]
+
{\bfa Default settings}
\HL
 
\NC {\bf Size or style} \NC {\bf Code}          \NC {\bf Typesetting} \NC\NR
 
\HL
 
\NC math                \NC \type{\frac{1}{3}}  \NC \m{\frac{1}{3}}  \NC\NR
 
\NC display            \NC \type{\dfrac{1}{3}}  \NC \m{\dfrac{1}{3}}  \NC\NR
 
\NC script              \NC \type{\xfrac{1}{3}}  \NC \m{\xfrac{1}{3}}  \NC\NR
 
\NC scriptscript        \NC \type{\sfrac{1}{3}}  \NC \m{\sfrac{1}{3}}  \NC\NR
 
\NC scriptscript        \NC \type{\xxfrac{1}{3}} \NC \m{\xxfrac{1}{3}} \NC\NR
 
\NC semi-horizontal    \NC \type{\vfrac{1}{3}}  \NC \m{\vfrac{1}{3}}  \NC\NR
 
\NC horizontal          \NC \type{\hfrac{1}{3}}  \NC \m{\hfrac{1}{3}}  \NC\NR
 
\NC continued          \NC \type{\cfrac{1}{3}}  \NC \m{\cfrac{1}{3}}  \NC\NR
 
\NC text                \NC \type{\tfrac{1}{3}}  \NC \m{\tfrac{1}{3}}  \NC\NR
 
\stoptabulate
 
 
 
\title{Binomial coefficients}
 
 
 
\startcolumns[n=2]
 
  
\subject{Default settings}
+
                          {\it Latin Modern} \getbuffer
                          \subsubject{Latin Modern} \getbuffer
+
\switchtobodyfont[pagella] {\it Pagella}      \getbuffer
\switchtobodyfont[pagella] \subsubject{Pagella}      \getbuffer
+
\switchtobodyfont[stixtwo] {\it STIX Two}    \getbuffer
\switchtobodyfont[stixtwo] \subsubject{STIX Two}    \getbuffer
+
%\switchtobodyfont[lucidaot] \subsubject{Lucida}      \getbuffer
\switchtobodyfont[lucidaot] \subsubject{Lucida}      \getbuffer
 
  
 
\column[yes]
 
\column[yes]
Line 145: Line 125:
  
 
\switchtobodyfont[modern]
 
\switchtobodyfont[modern]
\subject{Default settings}
+
{\bfa With fences=parenthesis}
                           \subsubject{Latin Modern} \getbuffer
+
 
\switchtobodyfont[pagella] \subsubject{Pagella}      \getbuffer
+
                           {\it Latin Modern} \getbuffer
\switchtobodyfont[stixtwo] \subsubject{STIX Two}    \getbuffer
+
\switchtobodyfont[pagella] {\it Pagella}      \getbuffer
\switchtobodyfont[lucidaot] \subsubject{Lucida}      \getbuffer
+
\switchtobodyfont[stixtwo] {\it STIX Two}    \getbuffer
 +
%\switchtobodyfont[lucidaot] \subsubject{Lucida}      \getbuffer
  
 
\stopcolumns}
 
\stopcolumns}

Revision as of 18:39, 12 May 2024

Fractions

\frac typeset fraction, according to the current style. Others commands enforce a certain style :


\starttabulate[|l|l|l|]
\HL
\NC {\bf Size or style} \NC {\bf Code}           \NC {\bf Typesetting} \NC\NR
\HL
\NC math                \NC \type{\frac{1}{3}}   \NC \m{\frac{1}{3}}   \NC\NR
\NC display             \NC \type{\dfrac{1}{3}}  \NC \m{\dfrac{1}{3}}  \NC\NR
\NC script              \NC \type{\xfrac{1}{3}}  \NC \m{\xfrac{1}{3}}  \NC\NR
\NC scriptscript        \NC \type{\sfrac{1}{3}}  \NC \m{\sfrac{1}{3}}  \NC\NR
\NC scriptscript        \NC \type{\xxfrac{1}{3}} \NC \m{\xxfrac{1}{3}} \NC\NR
\NC semi-horizontal     \NC \type{\vfrac{1}{3}}  \NC \m{\vfrac{1}{3}}  \NC\NR
\NC horizontal          \NC \type{\hfrac{1}{3}}  \NC \m{\hfrac{1}{3}}  \NC\NR
\NC continued           \NC \type{\cfrac{1}{3}}  \NC \m{\cfrac{1}{3}}  \NC\NR
\NC text                \NC \type{\tfrac{1}{3}}  \NC \m{\tfrac{1}{3}}  \NC\NR
\stoptabulate

Different behaviors for inline and display mode

\startbuffer[frac]
\frac{1}{2} + \dfrac{1}{2} - \sfrac{1}{2} - \xfrac{1}{2}  - \xxfrac{1}{2} + \vfrac{1}{2} + \hfrac{1}{2}  + \tfrac{1}{2}
\stopbuffer

\framed[frame=off,align=normal]{%   <=== just to improve wiki rendering
Each time, we display the different style:

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

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


Fractions of fractions

\startbuffer[frac]
\frac{1}{2} + \dfrac{1}{2} - \sfrac{1}{2} - \xfrac{1}{2}  - \xxfrac{1}{2} + \vfrac{1}{2} + \hfrac{1}{2}  + \tfrac{1}{2}
\stopbuffer

\framed[frame=off,align=normal]{%   <=== just to improve wiki rendering
Now fraction of fractions:

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


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

With \tex{m}  (inline mode) and \tex{cfrac} (continued):
\m{\cfrac
  {\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]

\framed[frame=off,align=normal]{%   <=== just to improve wiki rendering

\starttabulate[|l|l|]
\NC \type{\binom{n}{k}}  \NC $\binom{n}{k}$    \NC\NR
\NC \type{\tbinom{n}{k}} \NC $\tbinom{n}{k}$   \NC\NR
\NC \type{\dbinom{n}{k}} \NC $\dbinom{n}{k}$   \NC\NR
\stoptabulate
\stopbuffer

\title{Binomial coefficients}

\startcolumns[n=2,separator=rule]

{\bfa Default settings}

                           {\it Latin Modern} \getbuffer
\switchtobodyfont[pagella] {\it Pagella}      \getbuffer
\switchtobodyfont[stixtwo] {\it STIX Two}     \getbuffer
%\switchtobodyfont[lucidaot] \subsubject{Lucida}      \getbuffer

\column[yes]

\setupmathfractions[binom][fences=parenthesis]

\switchtobodyfont[modern]
{\bfa With fences=parenthesis}

                           {\it Latin Modern} \getbuffer
\switchtobodyfont[pagella] {\it Pagella}      \getbuffer
\switchtobodyfont[stixtwo] {\it STIX Two}     \getbuffer
%\switchtobodyfont[lucidaot] \subsubject{Lucida}      \getbuffer

\stopcolumns}

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

binomialcoefficients.png