# Andika fractions

I have hand made the exercise with svg. See attachment. It was very cumbersome.

If I could write the étude in markdown and then do pandoc magic I could perhaps learn how to create a library of basic exercises. As simple as possible, but also as "schoolbook-like" as possible with Andika's open four, seven with a bar etc.

Below the markdown that I hope to learn how to tweak with more complex pandoc command line arguments than this:

~/lk$pandoc --variable mainfont="Andika" lk-markdown-base-file.md --pdf-engine=xelatex -o lk-md-xelatex-pdf.pdf  I copied that line from https://pandoc.org/demos.html, here's the markdown: Andika fractions 0123456789$\frac{1}{1}+\frac{1}{4}=\frac{4}{4}·\frac{1}{1}+\frac{1}{1}·\frac{1}{4}=\frac{4}{4}+\frac{1}{4}=\frac{5}{4}\frac{1}{2}+\frac{1}{5}=\frac{5}{5}·\frac{1}{2}+\frac{2}{2}·\frac{1}{5}=\frac{5}{10}+\frac{2}{10}=\frac{1}{3}+\frac{1}{6}=\frac{6}{6}·\frac{1}{3}+\frac{3}{3}·\frac{1}{6}=\frac{6}{18}+\frac{1}{4}+\frac{1}{7}=\frac{7}{7}·\frac{1}{4}+\frac{4}{4}·\frac{1}{7}=\frac{1}{5}+\frac{1}{8}=\frac{8}{8}·\frac{1}{5}+\frac{5}{5}·\frac{1}{6}+\frac{1}{9}=\frac{9}{9}·\frac{1}{6}+\frac{1}{7}+\frac{1}{10}=\frac{10}{10}·\frac{1}{8}+\frac{1}{11}=\frac{1}{9}+$ If I could make such a fractions exercise with Andika without having to program svg, that would be fantastic! • Hi Jonas, the pdf with "Font Features for Andika" lists variants (e.g. "open four") of the numerals 1, 4, 6, 7 and 9, see bottom of page: software.sil.org/wp-content/uploads/sites/19/2015/12/… Best regards. //Erik – Erik Josefsson Jan 26 at 20:44 • @ErikJosefsson I see, one has to generate it first for a quick preview scripts.sil.org/ttw/fonts2go.cgi – Jonas Stein Jan 26 at 20:59 • @JonasStein That link was new to me, and I did not know there were two variants of Andika. I have only installed (on debian) aptitude install fonts-sil-andika without any particulars. I guess that if I have a pre-made font generated by the SIL-script site, I don't have to specify the which variant of the numerals I want to use? – Erik Josefsson Jan 27 at 7:52 ## 2 Answers TL;DR: You need to tell pandoc, which font to use in the YAML header: --- mainfont: Andika mainfontoptions: - CharacterVariant=1 - CharacterVariant=4 - CharacterVariant=6 - CharacterVariant=7 mathspec: true mathfont: Andika mathfontoptions: - CharacterVariant=1 - CharacterVariant=4 - CharacterVariant=6 - CharacterVariant=7 --- # Markdown below  This works only for XeLaTeX. If you need a solution that works with LuaLaTeX see Mico's answer. The open digits can be activated by using the otf font features¹. You can do that with fontspec: \documentclass{article} \usepackage{fontspec} \setmainfont[CharacterVariant={1,4,6,7}]{Andika} \usepackage{parskip} \setlength{\parindent}{0pt} \setlength{\parskip}{6pt plus 2pt minus 1pt} \begin{document} Andika fractions 0123456789 \end{document}  Andika now works in text mode but not in math mode. To use Andika also in math mode you have to load mathspec instead of fontspec: \documentclass{article} \usepackage{mathspec} \setmainfont[CharacterVariant={1,4,6,7}]{Andika} \setmathfont(Digits,Latin)[CharacterVariant={1,4,6,7}]{Andika} \usepackage{parskip} \setlength{\parindent}{0pt} \setlength{\parskip}{6pt plus 2pt minus 1pt} \begin{document} Andika fractions 0123456789 $$\frac{1}{1}+\frac{1}{4}=\frac{4}{4}\cdot\frac{1}{1}+\frac{1}{1}\cdot\frac{1}{4}=\frac{4}{4}+\frac{1}{4}=\frac{5}{4}$$ $$\frac{1}{2}+\frac{1}{5}=\frac{5}{5}\cdot\frac{1}{2}+\frac{2}{2}\cdot\frac{1}{5}=\frac{5}{10}+\frac{2}{10}=$$ $$\frac{1}{3}+\frac{1}{6}=\frac{6}{6}\cdot\frac{1}{3}+\frac{3}{3}\cdot\frac{1}{6}=\frac{6}{18}+$$ $$\frac{1}{4}+\frac{1}{7}=\frac{7}{7}\cdot\frac{1}{4}+\frac{4}{4}\cdot\frac{1}{7}=$$ $$\frac{1}{5}+\frac{1}{8}=\frac{8}{8}\cdot\frac{1}{5}+\frac{5}{5}\cdot$$ $$\frac{1}{6}+\frac{1}{9}=\frac{9}{9}\cdot\frac{1}{6}+$$ $$\frac{1}{7}+\frac{1}{10}=\frac{10}{10}\cdot$$ $$\frac{1}{8}+\frac{1}{11}=$$ $$\frac{1}{9}+$$ \end{document}  To use this solution with pandoc you have to tell it to use mathspec and specify the main and math font with the option above. You can do that in the YAML header²: --- mainfont: Andika mainfontoptions: - CharacterVariant=1 - CharacterVariant=4 - CharacterVariant=6 - CharacterVariant=7 mathspec: true mathfont: Andika mathfontoptions: - CharacterVariant=1 - CharacterVariant=4 - CharacterVariant=6 - CharacterVariant=7 --- Andika fractions 0123456789$\frac{1}{1}+\frac{1}{4}=\frac{4}{4}\cdot\frac{1}{1}+\frac{1}{1}\cdot\frac{1}{4}=\frac{4}{4}+\frac{1}{4}=\frac{5}{4}\frac{1}{2}+\frac{1}{5}=\frac{5}{5}\cdot\frac{1}{2}+\frac{2}{2}\cdot\frac{1}{5}=\frac{5}{10}+\frac{2}{10}=\frac{1}{3}+\frac{1}{6}=\frac{6}{6}\cdot\frac{1}{3}+\frac{3}{3}\cdot\frac{1}{6}=\frac{6}{18}+\frac{1}{4}+\frac{1}{7}=\frac{7}{7}\cdot\frac{1}{4}+\frac{4}{4}\cdot\frac{1}{7}=\frac{1}{5}+\frac{1}{8}=\frac{8}{8}\cdot\frac{1}{5}+\frac{5}{5}\cdot\frac{1}{6}+\frac{1}{9}=\frac{9}{9}\cdot\frac{1}{6}+\frac{1}{7}+\frac{1}{10}=\frac{10}{10}\cdot\frac{1}{8}+\frac{1}{11}=\frac{1}{9}+$ You can call pandoc now as usual: $ pandoc input.md --pdf-engine=xelatex -o output.pdf


–––

1. You can use otfinfo -f Andika-R.ttf to list all available font features.
2. Multiple option values can be set with a simple YAML sequence.
• Wow! I have spent days trying to make this happen on my own!! Is it possible to have all CharacterVariants active (i.e. 1, 4, 6, 7 and 9)? I tried to list with comma separation, but this did not work: CharacterVariant=4,7 – Erik Josefsson Jan 26 at 11:17
• @ErikJosefsson If you want to have more than one feature activated, you need to put curly braces around them: CharacterVariant={4,7} – DG' Jan 26 at 11:19
• Sorry, didn't work with curly braces {4,7} in the YAML header: --- mainfont: Andika mainfontoptions: CharacterVariant={4,7} mathspec: true mathfont: Andika mathfontoptions: CharacterVariant={4,7} --- This is what pandoc said: Error producing PDF. ! Missing number, treated as zero. <to be read again> \protect l.21 \ifxetex I think I have all of Andika installed since I made the svg with font-feature-settings: "dig1" 1, "dig4" 1, "dg69" 1, "dig7" 1; Almost there! :-) Thanks!! – Erik Josefsson Jan 26 at 11:32
• You are right. Doesn't work that way. You have to use a YAML sequence. See edit. – DG' Jan 26 at 15:47

Here's a solution that works with both LuaLaTeX and XeLaTeX, while using the non-default variants of the numerals 1, 4, 6, 7, and 9. In addition, it employs an array environment, to help align all fraction terms, + symbols, and = symbols horizontally as well as vertically.

Observe that since Andika is a text font, not a math font, only the numerals in the math terms employ Andika; all other glyphs (such as + and =) are rendered using Latin Modern Math.

The code below actually presents two solutions, rather than just one solution. The first uses display-style math, while the secod uses text-style math. The difference is most readily apparent in the size of the \frac terms.

\documentclass{article}
\usepackage{array}    % for '\newcolumntype' macro
\newcolumntype{C}{>{{}}c<{{}}}       % column type for = and + operators
\newcolumntype{H}{>{\displaystyle}c}

\usepackage{unicode-math}

\setmainfont{Andika}[CharacterVariant={1,4,6,7}]
\setmathfont{Latin Modern Math}
\setmathfont{Andika}[range=up/{num},
CharacterVariant={1,4,6,7}]

\begin{document}
Andika numerals 0123456789

Solution 1: display-style math and fractions
$\setlength{\arraycolsep}{0pt} \begin{array}{*{8}{HC}H} \frac{1}{1} &+&\frac{1}{4} &=& \frac{4}{4} &\cdot& \frac{1}{1} &+& \frac{1}{1} &\cdot& \frac{1}{4} &=& \frac{4}{4} &+&\frac{1}{4} &=& \frac{5}{4}\\ \addlinespace \frac{1}{2} &+&\frac{1}{5} &=& \frac{5}{5} &\cdot& \frac{1}{2} &+& \frac{2}{2} &\cdot& \frac{1}{5} &=& \frac{5}{10} &+&\frac{2}{10}&=& \\ \addlinespace \frac{1}{3} &+&\frac{1}{6} &=& \frac{6}{6} &\cdot& \frac{1}{3} &+& \frac{3}{3} &\cdot& \frac{1}{6} &=& \frac{6}{18} &+&\\ \addlinespace \frac{1}{4} &+&\frac{1}{7} &=& \frac{7}{7} &\cdot& \frac{1}{4} &+& \frac{4}{4} &\cdot& \frac{1}{7} &=& \\ \addlinespace \frac{1}{5} &+&\frac{1}{8} &=& \frac{8}{8} &\cdot& \frac{1}{5} &+& \frac{5}{5} &\cdot& \\ \addlinespace \frac{1}{6} &+&\frac{1}{9} &=& \frac{9}{9} &\cdot& \frac{1}{6} &+& \\ \addlinespace \frac{1}{7} &+&\frac{1}{10} &=& \frac{10}{10} &\cdot& \\ \addlinespace \frac{1}{8} &+&\frac{1}{11} &=& \\ \addlinespace \frac{1}{9} &+&\\ \end{array}$

Solution 2: text-style math and fractions
$\setlength{\arraycolsep}{0pt} \begin{array}{*{8}{cC}c} \frac{1}{1} &+&\frac{1}{4} &=& \frac{4}{4} &\cdot& \frac{1}{1} &+& \frac{1}{1} &\cdot& \frac{1}{4} &=& \frac{4}{4} &+&\frac{1}{4} &=& \frac{5}{4}\\ \addlinespace \frac{1}{2} &+&\frac{1}{5} &=& \frac{5}{5} &\cdot& \frac{1}{2} &+& \frac{2}{2} &\cdot& \frac{1}{5} &=& \frac{5}{10} &+&\frac{2}{10}&=& \\ \addlinespace \frac{1}{3} &+&\frac{1}{6} &=& \frac{6}{6} &\cdot& \frac{1}{3} &+& \frac{3}{3} &\cdot& \frac{1}{6} &=& \frac{6}{18} &+&\\ \addlinespace \frac{1}{4} &+&\frac{1}{7} &=& \frac{7}{7} &\cdot& \frac{1}{4} &+& \frac{4}{4} &\cdot& \frac{1}{7} &=& \\ \addlinespace \frac{1}{5} &+&\frac{1}{8} &=& \frac{8}{8} &\cdot& \frac{1}{5} &+& \frac{5}{5} &\cdot& \\ \addlinespace \frac{1}{6} &+&\frac{1}{9} &=& \frac{9}{9} &\cdot& \frac{1}{6} &+& \\ \addlinespace \frac{1}{7} &+&\frac{1}{10} &=& \frac{10}{10} &\cdot& \\ \addlinespace \frac{1}{8} &+&\frac{1}{11} &=& \\ \addlinespace \frac{1}{9} &+&\\ \end{array}$
\end{document}

• This is very helpful and useful and fantastic! You also helped solve how to send more than one CharacterVariant through pandoc's YAML code --- mainfont: Andika mainfontoptions: [CharacterVariant=1, CharacterVariant=4, CharacterVariant=6, CharacterVariant=7] mathspec: true mathfont: Andika mathfontoptions: [CharacterVariant=1, CharacterVariant=4, CharacterVariant=6, CharacterVariant=7] --- code I'll try to unwrap the snippet {C}{>{{}}c<{{}}} to see if I can reproduce that level of precision myself: code \begin{array}{*{8}{HC}H} code Again, thank you! //Erik – Erik Josefsson Jan 26 at 14:29