-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tex
72 lines (61 loc) · 1.87 KB
/
main.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
\documentclass[12pt, a4paper, addpoints]{exam}
\usepackage{amsmath} % For mathematical symbols
\usepackage{multicol} % For multi-column layout
\usepackage{pgfmath} % For math parsing and calculations
% Define the \expandbinomials command
\newcommand{\expandbinomials}[4]{%
% Compute intermediate terms (A, B, C)
\pgfmathparse{#1*#3} \let\A\pgfmathresult % A = a*c
\pgfmathparse{#1*#4 + #2*#3} \let\B\pgfmathresult % B = a*d + b*c
\pgfmathparse{#2*#4} \let\C\pgfmathresult % C = b*d
% Compute absolute values and signs for A, B, C
\pgfmathparse{abs(\A)} \let\absA\pgfmathresult
\pgfmathparse{abs(\B)} \let\absB\pgfmathresult
\pgfmathparse{abs(\C)} \let\absC\pgfmathresult
% Correctly handle the signs
\ifnum\A>0 \def\signA{+} \else \def\signA{-} \fi
\ifnum\B>0 \def\signB{+} \else \def\signB{-} \fi
\ifnum\C>0 \def\signC{+} \else \def\signC{-} \fi
% Print the entire expression in math mode
\[
\ifnum\A=-1
-x^2
\else
\ifnum\A=1
x^2
\else
\pgfmathprintnumber{\A}x^2
\fi
\fi
\ifnum\B=0
\else
\signB\ifnum\absB=1 x \else \pgfmathprintnumber{\absB}x\fi
\fi
\ifnum\C=0
\else
\signC\pgfmathprintnumber{\absC}
\fi
\]
}
\begin{document}
\begin{questions}
\LARGE
\question
Factor the following quadratic expressions.
\setlength{\columnsep}{50pt}
\begin{multicols}{2}
\begin{parts}
% Example 1: Generates the quadratic from (3x \part \expandbinomials{1}{1}{5}{7}
\part \expandbinomials{2}{3}{1}{1}
\part \expandbinomials{1}{1}{11}{5}
\part \expandbinomials{7}{11}{1}{1}
\part \expandbinomials{1}{1}{13}{2}
\part \expandbinomials{5}{7}{1}{1}
\part \expandbinomials{1}{1}{3}{2}
\part \expandbinomials{3}{5}{1}{1}
\part \expandbinomials{1}{1}{2}{11}
\part \expandbinomials{11}{13}{1}{1}
\end{parts}
\end{multicols}
\end{questions}
\end{document}