Singlet Problem

This example shows how to use pygacity singlet to build a quick single-problem document for testing and previewing a LaTeX problem source file. All files for this example are in the examples/singlet/ directory.

The working directory contains just one problem source file:

singlet/
└── radius.tex       # a pythontex problem: area → radius

The Problem Source File

\begin{pycode}
from math import pi, sqrt
A = 0.25 # cm
# A = pi * r**2 ==> r = sqrt(A/pi)
r = sqrt(A/pi)
AnsSet.register(1, label=r'\(r\) (cm)', value=r)
\end{pycode}
A circle has area $A$ = \py{A} cm$^2$.  What is its radius?

\ifshowsolutions

Solution: Since area $A$ and radius $r$ of a circle are related by
\[
    A = \pi r^2
\]
we know that
\[
    r = \sqrt{\frac{A}{\pi}}
\]
Using the value of area provided:

\begin{align*}
r & = \sqrt{\frac{\py{A}}{\py{f'{pi:.4f}'}}}\\
  & = \py{f'{r:.2f}'}\ \mbox{cm.}
\end{align*}

\fi

This problem demonstrates the full pygacity workflow in miniature:

  • A pycode block computes the radius from the given area using standard Python (math.pi and math.sqrt).

  • AnsSet.register records the answer so it appears in the answer set document.

  • \py{...} commands embed the computed values directly in the typeset problem statement and solution.

  • The \ifshowsolutions / \fi guard keeps the solution hidden in the student copy and visible in the instructor copy.

Building the Document

From inside the singlet/ directory, run:

pygacity singlet radius.tex

Pygacity assembles a minimal LaTeX document around the problem fragment, runs latexmk with XeLaTeX (and pythontex, because the file contains a pycode block), and writes all output to the build-singlet/ directory.

Output

After a successful build, build-singlet/ contains:

  • radius-singlet.pdf — the student-facing document (solution hidden)

  • radius-singlet_soln.pdf — the instructor copy with the solution shown

  • buildfiles.zip / solnbuildfiles.zip — zipped LaTeX sources

  • tex_artifacts.zip — intermediate LaTeX artifacts

Student version (radius-singlet.pdf):

Student singlet PDF

Solutions version (radius-singlet_soln.pdf) — the solution is revealed and the computed numeric values are typeset by pythontex:

Solutions singlet PDF