Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
Populate a book's latex preamble from the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
runestonetest committed Jun 8, 2020
1 parent 400af9c commit 49dbc80
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 96 deletions.
16 changes: 7 additions & 9 deletions controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@
lp_build=ALL_WHICH_OPTIONS,
)

# create a simple index to provide a page of links
# - re build the book
# - list assignments
# - find assignments for a student
# - show totals for all students

# select acid, sid from code as T where timestamp = (select max(timestamp)
# from code where sid=T.sid and acid=T.acid);


@auth.requires_login()
def index():
Expand Down Expand Up @@ -116,6 +107,10 @@ def assignments():
)
for row in chapters_query:
chapter_labels.append(row.chapter_label)

# See `models/db_ebook.py` for course_attributes table
set_latex_preamble(course.base_course)

return dict(
coursename=auth.user.course_name,
confirm=False,
Expand Down Expand Up @@ -710,6 +705,9 @@ def grading():
for chapter_q in chapter_questions:
q_list.append(chapter_q.name)
chapter_labels[row.chapter_label] = q_list

set_latex_preamble(base_course)

return dict(
assignmentinfo=json.dumps(assignments),
students=searchdict,
Expand Down
4 changes: 4 additions & 0 deletions controllers/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ def doAssignment():
else "false"
)

set_latex_preamble(course.base_course)

return dict(
course=course,
course_name=auth.user.course_name,
Expand Down Expand Up @@ -998,6 +1000,8 @@ def practice():
result_sourcedid=practice_grade.lis_result_sourcedid,
)

set_latex_preamble(course.base_course)

return dict(
course=course,
q=questioninfo,
Expand Down
21 changes: 21 additions & 0 deletions models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,27 @@ def formatter(self, value):

auth.define_tables(username=True, signature=False, migrate=table_migrate_prefix + "")

# Because so many pages rely on `views/_sphinx_static_file.html` it makes
# sense to provide some default values for variables used in the template here
# The latex_preamble attribute can be used for any custom latex macros used in
# the text, that need to be available for grading, assignments, and practice
# This is used in nearly every PreTeXt book.
request.latex_preamble = ""


def set_latex_preamble(base_course: str):
# See `models/db_ebook.py` for course_attributes table
bc = db(db.courses.course_name == base_course).select().first()
res = (
db(
(db.course_attributes.course_id == bc.id)
& (db.course_attributes.attr == "latex_macros")
)
.select()
.first()
)
request.latex_preamble = res.value if res else ""


## configure email
mail = auth.settings.mailer
Expand Down
88 changes: 1 addition & 87 deletions views/_sphinx_static_files.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,93 +52,7 @@
TagSide: "right",
TagIndent: ".8em",
Macros: {
orderof: ["{\\sim #1}", 1],
Z: "{\\mathbb{Z}}",
reals: "{\\mathbb{R}}",
real: ["{\\mathbb{R}^{#1}}", 1],
complexes: "{\\mathbb{C}}",
complex: ["{\\mathbb{C}^{#1}}", 1],
conjugate: ["{\\overline{#1}}", 1],
modulus: ["{\\left\\lvert#1\\right\\rvert}", 1],
zerovector: "{\\vect{0}}",
zeromatrix: "{\\mathcal{O}}",
innerproduct: ["{\\left\\langle#1,\\,#2\\right\\rangle}", 2],
norm: ["{\\left\\lVert#1\\right\\rVert}", 1],
dimension: ["{\\dim\\left(#1\\right)}", 1],
nullity: ["{n\\left(#1\\right)}", 1],
rank: ["{r\\left(#1\\right)}", 1],
ds: "{\\oplus}",
detname: ["{\\det\\left(#1\\right)}", 1],
detbars: ["{\\left\\lvert#1\\right\\rvert}", 1],
trace: ["{t\\left(#1\\right)}", 1],
sr: ["{#1^{1/2}}", 1],
spn: ["{\\left\\langle#1\\right\\rangle}", 1],
nsp: ["{\\mathcal{N}\\!\\left(#1\\right)}", 1],
csp: ["{\\mathcal{C}\\!\\left(#1\\right)}", 1],
rsp: ["{\\mathcal{R}\\!\\left(#1\\right)}", 1],
lns: ["{\\mathcal{L}\\!\\left(#1\\right)}", 1],
per: ["{#1^\\perp}", 1],
augmented: ["{\\left\\lbrack\\left.#1\\,\\right\\rvert\\,#2\\right\\rbrack}", 2],
linearsystem: ["{\\mathcal{LS}\\!\\left(#1,\\,#2\\right)}", 2],
homosystem: ["{\\linearsystem{#1}{\\zerovector}}", 1],
rowopswap: ["{R_{#1}\\leftrightarrow R_{#2}}", 2],
rowopmult: ["{#1R_{#2}}", 2],
rowopadd: ["{#1R_{#2}+R_{#3}}", 3],
leading: ["{\\boxed{#1}}", 1],
rref: "{\\xrightarrow{\\text{RREF}}}",
elemswap: ["{E_{#1,#2}}", 2],
elemmult: ["{E_{#2}\\left(#1\\right)}", 2],
elemadd: ["{E_{#2,#3}\\left(#1\\right)}", 3],
scalarlist: ["", 2],
vect: ["{\\mathbf{#1}}", 1],
colvector: ["{\\begin{bmatrix}#1\\end{bmatrix}}", 1],
vectorcomponents: ["{\\colvector{#1_{1}\\\\#1_{2}\\\\#1_{3}\\\\\\vdots\\\\#1_{#2}}}", 2],
vectorlist: ["{\\vect{#1}_{1},\\,\\vect{#1}_{2},\\,\\vect{#1}_{3},\\,\\ldots,\\,\\vect{#1}_{#2}}", 2],
vectorentry: ["{\\left\\lbrack#1\\right\\rbrack_{#2}}", 2],
matrixentry: ["{\\left\\lbrack#1\\right\\rbrack_{#2}}", 2],
lincombo: ["{#1_{1}\\vect{#2}_{1}+#1_{2}\\vect{#2}_{2}+#1_{3}\\vect{#2}_{3}+\\cdots +#1_{#3}\\vect{#2}_{#3}}", 3],
matrixcolumns: ["{\\left\\lbrack\\vect{#1}_{1}|\\vect{#1}_{2}|\\vect{#1}_{3}|\\ldots|\\vect{#1}_{#2}\\right\\rbrack}", 2],
transpose: ["{#1^{t}}", 1],
inverse: ["{#1^{-1}}", 1],
submatrix: ["{#1\\left(#2|#3\\right)}", 3],
adj: ["{\\transpose{\\left(\\conjugate{#1}\\right)}}", 1],
adjoint: ["{#1^\\ast}", 1],
set: ["{\\left\\{#1\\right\\}}", 1],
setparts: ["{\\left\\lbrace#1\\,\\middle|\\,#2\\right\\rbrace}", 2],
card: ["{\\left\\lvert#1\\right\\rvert}", 1],
setcomplement: ["{\\overline{#1}}", 1],
charpoly: ["{p_{#1}\\left(#2\\right)}", 2],
eigenspace: ["{\\mathcal{E}_{#1}\\left(#2\\right)}", 2],
eigensystem: ["{\\lambda&=#2&\\eigenspace{#1}{#2}&=\\spn{\\set{#3}}}", 3],
geneigenspace: ["{\\mathcal{G}_{#1}\\left(#2\\right)}", 2],
algmult: ["{\\alpha_{#1}\\left(#2\\right)}", 2],
geomult: ["{\\gamma_{#1}\\left(#2\\right)}", 2],
indx: ["{\\iota_{#1}\\left(#2\\right)}", 2],
ltdefn: ["{#1\\colon #2\\rightarrow#3}", 3],
lteval: ["{#1\\left(#2\\right)}", 2],
ltinverse: ["{#1^{-1}}", 1],
restrict: ["", 2],
preimage: ["{#1^{-1}\\left(#2\\right)}", 2],
rng: ["{\\mathcal{R}\\!\\left(#1\\right)}", 1],
krn: ["{\\mathcal{K}\\!\\left(#1\\right)}", 1],
compose: ["", 2],
vslt: ["{\\mathcal{LT}\\left(#1,\\,#2\\right)}", 2],
isomorphic: "{\\cong}",
similar: ["{\\inverse{#2}#1#2}", 2],
vectrepname: ["{\\rho_{#1}}", 1],
vectrep: ["{\\lteval{\\vectrepname{#1}}{#2}}", 2],
vectrepinvname: ["{\\ltinverse{\\vectrepname{#1}}}", 1],
vectrepinv: ["{\\lteval{\\ltinverse{\\vectrepname{#1}}}{#2}}", 2],
matrixrep: ["{M^{#1}_{#2,#3}}", 3],
matrixrepcolumns: ["{\\left\\lbrack \\left.\\vectrep{#2}{\\lteval{#1}{\\vect{#3}_{1}}}\\right|\\left.\\vectrep{#2}{\\lteval{#1}{\\vect{#3}_{2}}}\\right|\\left.\\vectrep{#2}{\\lteval{#1}{\\vect{#3}_{3}}}\\right|\\ldots\\left|\\vectrep{#2}{\\lteval{#1}{\\vect{#3}_{#4}}}\\right.\\right\\rbrack}", 4],
cbm: ["{C_{#1,#2}}", 2],
jordan: ["{J_{#1}\\left(#2\\right)}", 2],
hadamard: ["{#1\\circ #2}", 2],
hadamardidentity: ["{J_{#1}}", 1],
hadamardinverse: ["{\\widehat{#1}}", 1],
lt: "{<}",
gt: "{>}",
amp: "{&}",
{{= request.latex_preamble}}
},
},
// HTML-CSS output Jax to be dropped for MathJax 3.0
Expand Down

0 comments on commit 49dbc80

Please sign in to comment.