4. Number Lines worksheet LaTeX

4.1. Sample number line worksheets

nlWS_plus_q

nlWS_plus_ans

nlWS_minus_neg_q

nlWS_minus_neg_ans

nlWS_minus_q

nlWS_minus_ans

nlWS_minus_pos_q

nlWS_minus_pos_ans

nlWS_plus_neg_q

nlWS_plus_neg_ans

nlWS_random_q

nlWS_random_ans


4.2. Splitting the LaTeX and modifying it to be built by python

The LaTeX from a single number lines equation is used as a starting point, split into 2 and modified.
The Worksheet template contains the preamble and the scaffold for the document.
The Diagram template contains the backtacking diagram LaTeX.

4.2.1. Worksheet template

The LaTeX number lines worksheet template is below.
 1\documentclass[leqno, 12pt]{article}
 2\usepackage{tikz}
 3\usetikzlibrary{positioning}
 4\usetikzlibrary {arrows.meta}
 5\usetikzlibrary{bending}
 6\usepackage[a4paper, portrait, margin=1cm]{geometry}
 7\pagestyle{empty}
 8
 9\def\jumpheight{10}
10\def\qgap{\rule[-1pt]{1.0em}{.25pt}}
11
12\def \HeadingQuestions {\section*{\Large Name: \underline{\hspace{8cm}} \hfill Date: \underline{\hspace{3cm}}} \vspace{-3mm}
13{Number lines: Questions} \vspace{1pt}\hrule}
14
15\begin{document}
16    \HeadingQuestions
17    \vspace{-1mm}
18    <<diagrams>>
19\end{document}
\documentclass[leqno, 12pt]{article} specifies that you are working with an article document. The leqno option is used to place equation numbers on the left side of the equations instead of the right side. The 12pt option sets the font size to 12 points.
\usepackage{multicol} is a LaTeX package that allows multi-column layouts in documents. It defines the multicols environment, which takes one argument that specifies the total number of columns, such as \begin{multicols}{2}.
The page heading is set by:
\def \HeadingQuestions {\section*{\Large Name: \underline{\hspace{8cm}} \hfill Date: \underline{\hspace{3cm}}} \vspace{-3mm} {number lines: Questions} \vspace{1pt}\hrule}
The macro \HeadingQuestions creates a section heading with the text β€œName: β€œ in very large bold text with an underline, followed by an umderlined space of 8cm, followed by the text β€œDate: β€œ in bold text with an underlined space of 3cm, followed by a horizontal line.
\def is a LaTeX command that defines a macro, which is a custom command that performs a specific set of actions.
\HeadingQuestions is the name of the macro being defined with the \def command.
The \section* command is used to create a section heading without a number, and the \Large command is used to make the heading text very large.
The \underline command is used to add a horizontal line under its text.
The \hspace command is used to add space on both sides of the heading text.
The \hrule command is used to create a horizontal line, which separates the heading from the remainder of the document.
\vspace{-5mm} is a command that adds vertical space to the document. The -5mm argument specifies that the space should be negative 5 millimeters. This means that the following text will be moved up by 5 millimeters.
\begin{multicols}{2} command creates 2 columns.
The \columnbreak command is used to force a column break at that point in the document. The command works by creating a vertical white space, which is big enough to move the text from the top of the current column to the top of the next column.
<<col1>> is placeholder text for the text that python will use to add the LaTeX for the number line diagrams in column 1.
<<col2>> is placeholder text for column 2.

4.2.2. Diagram template

The LaTeX number line diagram template for each diagram is below.
 1\begin{equation}
 2\begin{tikzpicture}[scale=0.75, baseline={([yshift=-1pt]current bounding box.north)}]
 3    % axis, arrow style to-to
 4    \draw[{To[scale=1.3]}-{To[scale=1.3]}, line width=1pt] (-10.4, 0) -- (10.4, 0);  
 5    % tick marks
 6    \foreach \x in {-10,-9,...,10}
 7        \draw[shift={(\x,0)},color=black, line width=1pt] (0pt,-14pt) -- (0pt,0pt);
 8    % numbers along each axis
 9    \foreach \x in {-10,0,10}
10        \draw[shift={(\x,-0.8)},color=black] node[font=\large,text height=12pt] {$\x$};
11    \draw[shift={(<<startval>>,-0.8)},color=black] node[font=\large,text height=12pt] {$<<startvaltxt>>$};
12    \draw[shift={(<<endval>>,-0.8)},color=black] node[font=\large,text height=12pt] {$<<endvaltxt>>$};
13    % dots
14    \filldraw[black] (<<startval>>,0) circle (4pt) node[above,yshift=-2pt] (a) {};
15    \filldraw[black] (<<endval>>,0) circle (4pt) node[above,yshift=-2pt] (b) {}; 
16    % arrow
17    \draw[-{To[scale=1.3, bend]},line width=1pt, color=black] (a.north)  .. controls  +(north:\jumpheight mm) and +(north:\jumpheight mm) .. node[above=2pt,font=\large,text height=10pt] {$<<changevaltxt>>$} (b.north); % for addition
18    % equation at right end
19    \node [font=\large, minimum width=30mm] at (11.0,1.2) {$<<equtxt>>$};
20\end{tikzpicture}
21\end{equation}

4.2.3. Question numbering

\begin{equation} and the end tag wrap around the tikzpicture so that a question number is added.
\begin{tikzpicture}[baseline={([yshift=-1pt]current bounding box.north)}] moves the tikzpicture and question number so that the question number is moved to the top left (set to the left in the documentclass).
The option baseline=(current bounding box.north) aligns the top of the bounding box of the TikZ picture with the baseline of the surrounding text.
[yshift=-1pt] can be modified to adjust their relative laignment at the top.

4.2.4. Placeholders to be replaced by python

The line \node[backtrack] (boxB) [right=1cm of boxA] {$<<boxB>>$} has a placeholder <<boxB>> which is replaced by python.
Other placeholders are tagged by << >>.