From 8789f20ba9479154077295a76d5b4bc463527c85 Mon Sep 17 00:00:00 2001
From: Bluesy1 <68259537+Bluesy1@users.noreply.github.com>
Date: Tue, 4 Jul 2023 17:16:33 -0700
Subject: [PATCH 1/2] Initial Pass at implementing a way to disable latex in
sections of pl questions
---
.../problem_bank_scripts.py | 20 +++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/problem_bank_scripts/problem_bank_scripts.py b/src/problem_bank_scripts/problem_bank_scripts.py
index 37a3f0a0..c8fa6a4f 100644
--- a/src/problem_bank_scripts/problem_bank_scripts.py
+++ b/src/problem_bank_scripts/problem_bank_scripts.py
@@ -1009,9 +1009,12 @@ def process_question_pl(source_filepath, output_path=None):
preamble = parsed_q["body_parts"].get("preamble", None)
#TODO: Remove Debugging print statement
#print(f"premable: {preamble}")
-
+
+ disable_latex_class = ' class="mathjax_ignore"'
+ latex = parsed_q['header'].get('latex', {})
+
if preamble:
- question_html = f"\n\n{ preamble }\n\n\n\n"
+ question_html = f"\n\n{ preamble }\n\n\n\n"
else:
question_html = f""
@@ -1041,6 +1044,12 @@ def process_question_pl(source_filepath, output_path=None):
question_html += f"\n\n\n"
+ latex_part = latex.get(part, {})
+ allow_latex = latex_part.get("question", True)
+
+ if not allow_latex:
+ question_html += '
\n'
+
if parsed_q["num_parts"] > 1:
question_html += f"""
\n
@@ -1070,14 +1079,17 @@ def process_question_pl(source_filepath, output_path=None):
if parsed_q["num_parts"] > 1:
question_html += "
\n
\n"
+ if not allow_latex:
+ question_html += "\n"
+
# Add pl-submission-panel and pl-answer-panel (if they exist)
subm_panel = parsed_q["body_parts_split"][part].get("pl-submission-panel", None)
q_panel = parsed_q["body_parts_split"][part].get("pl-answer-panel", None)
if subm_panel:
- question_html += f"\n{ subm_panel } \n"
+ question_html += f"\n{ subm_panel } \n"
if q_panel:
- question_html += f"\n{ q_panel } \n"
+ question_html += f"\n{ q_panel } \n"
# TODO: Add support for other panels here as well !
From 013f106b8f226ecd8d8b185bd9c051fcc76b6bf2 Mon Sep 17 00:00:00 2001
From: Bluesy1 <68259537+Bluesy1@users.noreply.github.com>
Date: Tue, 4 Jul 2023 17:55:08 -0700
Subject: [PATCH 2/2] Duplicate q07a to test new latex disabling code
---
.../problem_bank_scripts.py | 2 +-
.../q07c_symbolic-input-no-latex.md | 130 ++++++++++++++++++
.../q07c_symbolic-input-no-latex/info.json | 12 ++
.../question.html | 43 ++++++
.../q07c_symbolic-input-no-latex/server.py | 40 ++++++
.../q07c_symbolic-input-no-latex.md | 74 ++++++++++
.../q07c_symbolic-input-no-latex.md | 111 +++++++++++++++
7 files changed, 411 insertions(+), 1 deletion(-)
create mode 100644 tests/test_question_templates/question_expected_outputs/instructor/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
create mode 100644 tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/info.json
create mode 100644 tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/question.html
create mode 100644 tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/server.py
create mode 100644 tests/test_question_templates/question_expected_outputs/public/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
create mode 100644 tests/test_question_templates/question_inputs/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
diff --git a/src/problem_bank_scripts/problem_bank_scripts.py b/src/problem_bank_scripts/problem_bank_scripts.py
index c8fa6a4f..34d70cf2 100644
--- a/src/problem_bank_scripts/problem_bank_scripts.py
+++ b/src/problem_bank_scripts/problem_bank_scripts.py
@@ -1039,7 +1039,7 @@ def process_question_pl(source_filepath, output_path=None):
# Single and Multi-part question construction
for pnum in range(1, parsed_q["num_parts"] + 1):
- part = "part" + f"{pnum}"
+ part = f"part{pnum}"
q_type = parsed_q["header"][part]["type"]
question_html += f"\n\n\n"
diff --git a/tests/test_question_templates/question_expected_outputs/instructor/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md b/tests/test_question_templates/question_expected_outputs/instructor/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
new file mode 100644
index 00000000..7f03eb6d
--- /dev/null
+++ b/tests/test_question_templates/question_expected_outputs/instructor/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
@@ -0,0 +1,130 @@
+---
+title: Centripetal Motion
+topic: Template
+author: Michael Kudla
+source: original
+template_version: 1.4
+attribution: standard
+partialCredit: true
+singleVariant: false
+showCorrectAnswer: false
+outcomes:
+- 6.1.1.0
+- 6.1.1.1
+difficulty:
+- undefined
+randomization:
+- undefined
+taxonomy:
+- undefined
+span:
+- undefined
+length:
+- undefined
+tags:
+- unknown
+assets: null
+server:
+ imports: |
+ import random as rd; rd.seed(111)
+ import pandas as pd
+ import sympy as sp
+ import problem_bank_scripts.prairielearn as pl
+ import problem_bank_helpers as pbh
+ generate: |
+ data2 = pbh.create_data2()
+
+ # store phrases etc
+ data2["params"]["vars"]["title"] = 'Centripetal Motion'
+
+ # Declare math symbols to be used by sympy
+ m, v, r = sp.symbols('m v r')
+
+ # Describe the solution equation
+ F = m*v**2/r
+
+ # Answer to fill in the blank input stored as JSON.
+ data2['correct_answers']['part1_ans'] = pl.to_json(F)
+
+ # Update the data object with a new dict
+ data.update(data2)
+ prepare: 'pass
+
+ '
+ parse: 'pass
+
+ '
+ grade: 'pass
+
+ '
+part1:
+ type: symbolic-input
+ latex: false
+ pl-customizations:
+ label: $F_r = $
+ variables: m, v, r
+ weight: 1
+ allow-blank: false
+latex:
+ preamble: false
+ part1:
+ question: false
+ submission: false
+ answer: false
+myst:
+ substitutions:
+ params:
+ vars:
+ title: Centripetal Motion
+ correct_answers:
+ part1_ans:
+ _type: sympy
+ _value: m*v**2/r
+ _variables:
+ - v
+ - r
+ - m
+
+---
+# {{ params.vars.title }}
+This question is a duplicate of q07a_symbolic-input, demonstrating the ability to disable latex parsing and rendering.
+
+## Question Text
+
+Write the centripetal force $F_r$ in terms of the mass $m$, velocity $v$, and radius $r$.
+
+Note that it may not be necessary to use every variable. Use the following table as a reference for each variable:
+
+| For | Use |
+|----------|-------|
+| $m$ | m |
+| $v$ | v |
+| $r$ | r |
+
+### Answer Section
+
+### pl-submission-panel
+
+Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+### pl-answer-panel
+
+Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+## Rubric
+
+This should be hidden from students until after the deadline.
+
+## Solution
+
+This should never be revealed to students.
+
+## Comments
+
+These are random comments associated with this question.
+
+## Attribution
+
+Problem is licensed under the [CC-BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/).

\ No newline at end of file
diff --git a/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/info.json b/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/info.json
new file mode 100644
index 00000000..0c2b0838
--- /dev/null
+++ b/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/info.json
@@ -0,0 +1,12 @@
+{
+ "uuid": "e7c5ceab-90e7-3aaf-9b1f-c43ae7c6036d",
+ "title": "Centripetal Motion",
+ "topic": "Template",
+ "tags": [
+ "symbolic-input"
+ ],
+ "type": "v3",
+ "showCorrectAnswer": false,
+ "singleVariant": false,
+ "partialCredit": true
+}
\ No newline at end of file
diff --git a/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/question.html b/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/question.html
new file mode 100644
index 00000000..8e4d7fb2
--- /dev/null
+++ b/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/question.html
@@ -0,0 +1,43 @@
+
+
+This question is a duplicate of q07a_symbolic-input, demonstrating the ability to disable latex parsing and rendering.
+
+
+
+
+
+
+
+
+
+ Write the centripetal force $F_r$ in terms of the mass $m$, velocity $v$, and radius $r$.
+
+Note that it may not be necessary to use every variable. Use the following table as a reference for each variable:
+
+| For | Use |
+|----------|-------|
+| $m$ | m |
+| $v$ | v |
+| $r$ | r |
+
+
+
+
+
+
+Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+
+Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+
+
+
+
+
+---
+Problem is licensed under the [CC-BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/).

+
+
diff --git a/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/server.py b/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/server.py
new file mode 100644
index 00000000..73041f46
--- /dev/null
+++ b/tests/test_question_templates/question_expected_outputs/prairielearn/q07c_symbolic-input-no-latex/server.py
@@ -0,0 +1,40 @@
+import random as rd; rd.seed(111)
+import pandas as pd
+import sympy as sp
+import problem_bank_scripts.prairielearn as pl
+import problem_bank_helpers as pbh
+
+def imports(data):
+ import random as rd; rd.seed(111)
+ import pandas as pd
+ import sympy as sp
+ import problem_bank_scripts.prairielearn as pl
+ import problem_bank_helpers as pbh
+
+def generate(data):
+ data2 = pbh.create_data2()
+
+ # store phrases etc
+ data2["params"]["vars"]["title"] = 'Centripetal Motion'
+
+ # Declare math symbols to be used by sympy
+ m, v, r = sp.symbols('m v r')
+
+ # Describe the solution equation
+ F = m*v**2/r
+
+ # Answer to fill in the blank input stored as JSON.
+ data2['correct_answers']['part1_ans'] = pl.to_json(F)
+
+ # Update the data object with a new dict
+ data.update(data2)
+
+def prepare(data):
+ pass
+
+def parse(data):
+ pass
+
+def grade(data):
+ pass
+
diff --git a/tests/test_question_templates/question_expected_outputs/public/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md b/tests/test_question_templates/question_expected_outputs/public/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
new file mode 100644
index 00000000..9eca4510
--- /dev/null
+++ b/tests/test_question_templates/question_expected_outputs/public/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
@@ -0,0 +1,74 @@
+---
+title: Centripetal Motion
+topic: Template
+author: Michael Kudla
+source: original
+template_version: 1.4
+attribution: standard
+partialCredit: true
+singleVariant: false
+showCorrectAnswer: false
+outcomes:
+- 6.1.1.0
+- 6.1.1.1
+difficulty:
+- undefined
+randomization:
+- undefined
+taxonomy:
+- undefined
+span:
+- undefined
+length:
+- undefined
+tags:
+- unknown
+assets: null
+part1:
+ type: symbolic-input
+ latex: false
+ pl-customizations:
+ label: $F_r = $
+ variables: m, v, r
+ weight: 1
+ allow-blank: false
+latex:
+ preamble: false
+ part1:
+ question: false
+ submission: false
+ answer: false
+myst:
+ substitutions:
+ params_vars_title: Centripetal Motion
+---
+# {{ params_vars_title }}
+This question is a duplicate of q07a_symbolic-input, demonstrating the ability to disable latex parsing and rendering.
+
+## Question Text
+
+Write the centripetal force $F_r$ in terms of the mass $m$, velocity $v$, and radius $r$.
+
+Note that it may not be necessary to use every variable. Use the following table as a reference for each variable:
+
+| For | Use |
+|----------|-------|
+| $m$ | m |
+| $v$ | v |
+| $r$ | r |
+
+### Answer Section
+
+### pl-submission-panel
+
+Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+### pl-answer-panel
+
+Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+## Attribution
+
+Problem is licensed under the [CC-BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/).

\ No newline at end of file
diff --git a/tests/test_question_templates/question_inputs/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md b/tests/test_question_templates/question_inputs/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
new file mode 100644
index 00000000..95c45688
--- /dev/null
+++ b/tests/test_question_templates/question_inputs/q07c_symbolic-input-no-latex/q07c_symbolic-input-no-latex.md
@@ -0,0 +1,111 @@
+---
+title: Centripetal Motion
+topic: Template
+author: Michael Kudla
+source: original
+template_version: 1.4
+attribution: standard
+partialCredit: true
+singleVariant: false
+showCorrectAnswer: false
+outcomes:
+- 6.1.1.0
+- 6.1.1.1
+difficulty:
+- undefined
+randomization:
+- undefined
+taxonomy:
+- undefined
+span:
+- undefined
+length:
+- undefined
+tags:
+- unknown
+assets:
+server:
+ imports: |
+ import random as rd; rd.seed(111)
+ import pandas as pd
+ import sympy as sp
+ import prairielearn as pl
+ import problem_bank_helpers as pbh
+ generate: |
+ data2 = pbh.create_data2()
+
+ # store phrases etc
+ data2["params"]["vars"]["title"] = 'Centripetal Motion'
+
+ # Declare math symbols to be used by sympy
+ m, v, r = sp.symbols('m v r')
+
+ # Describe the solution equation
+ F = m*v**2/r
+
+ # Answer to fill in the blank input stored as JSON.
+ data2['correct_answers']['part1_ans'] = pl.to_json(F)
+
+ # Update the data object with a new dict
+ data.update(data2)
+ prepare: |
+ pass
+ parse: |
+ pass
+ grade: |
+ pass
+part1:
+ type: symbolic-input
+ latex: false
+ pl-customizations:
+ label: $F_r = $
+ variables: "m, v, r"
+ weight: 1
+ allow-blank: false
+latex:
+ preamble: false
+ part1:
+ question: false
+ submission: false
+ answer: false
+---
+# {{ params.vars.title }}
+
+This question is a duplicate of q07a_symbolic-input, demonstrating the ability to disable latex parsing and rendering.
+
+## Question Text
+
+Write the centripetal force $F_r$ in terms of the mass $m$, velocity $v$, and radius $r$.
+
+Note that it may not be necessary to use every variable. Use the following table as a reference for each variable:
+
+| For | Use |
+|----------|-------|
+| $m$ | m |
+| $v$ | v |
+| $r$ | r |
+
+
+### Answer Section
+
+### pl-submission-panel
+
+Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+### pl-answer-panel
+
+Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
+Please remove this section if it is not application for this question.
+
+## Rubric
+
+This should be hidden from students until after the deadline.
+
+## Solution
+
+This should never be revealed to students.
+
+## Comments
+
+These are random comments associated with this question.