📜 ⬆️ ⬇️

LaTex: Exercise

In order for the older child to give examples for addition and subtraction in a column, he wrote a script for Groovy, which generates LaTeX with examples.
The goal was to practice in the groove, well, tired of writing examples by hand.

I didn’t write anything at the late in the past, but I knew from Uni and why I needed it.
Hour two fucking with how to make the desired type of column on LaTeX.
To work with LaTeX put the appropriate packages from CygWin.

Here is the script, I hope someone will come in handy:

////////////////////////////////////////////////////
int n = 30
def f1 = new File("d:\\temp\\ex.tex")
def f2 = new File("d:\\temp\\sol.tex")
/////////////////////////////////////////////////////

def r = new Random(System.currentTimeMillis())

f1.delete();
f2.delete();

def header = """
\\documentclass[a4paper,12pt,twocolumn]{article}
\\begin{document} \n"""

f1<< header
f2<< header

n.times {

int a = r.nextInt(10000)
int b = r.nextInt(10000)
boolean plus = r.nextBoolean()
if (a<b) { def t =a; a= b; b = t}
int c = plus?a+b:ab

def sign = plus?"+":"-"

f1<< """\$\$ \\frac{$sign \\begin{array}{rcc}
$a \\\\
$b
\\end{array}}{} \$\$\n"""

f2<< """\$\$ \\frac{$sign \\begin{array}{rcc}
$a \\\\
$b
\\end{array}}{$c} \$\$\n"""
}

def footer = """
\\end{document} \n"""

f1<<footer
f2<<footer

')
Here's what it looks like:

image

PS The most suitable blog, like - development. Or move to some other?

Source: https://habr.com/ru/post/108431/


All Articles