Skip to content

Stack static improvements#2779

Open
geoo89 wants to merge 5 commits intoPreTeXtBook:masterfrom
IDEMSInternational:stack-static-improvements
Open

Stack static improvements#2779
geoo89 wants to merge 5 commits intoPreTeXtBook:masterfrom
IDEMSInternational:stack-static-improvements

Conversation

@geoo89
Copy link
Contributor

@geoo89 geoo89 commented Jan 29, 2026

Adds support for a variety of STACK features, such as most existing input types and images, and improves error handling. A few example questions have been added to the sample article. (I plan to create a STACK example in the examples folder with a more detailed test suite.)

Also fixes a bug in the HTML rendering of STACK questions featuring multi-line latex, see #2778

@geoo89 geoo89 force-pushed the stack-static-improvements branch from 1edc49f to cc2586a Compare February 16, 2026 14:02
@geoo89 geoo89 marked this pull request as ready for review February 16, 2026 14:03
@geoo89 geoo89 changed the title Stack static improvements (WIP) Stack static improvements Feb 16, 2026
@geoo89 geoo89 force-pushed the stack-static-improvements branch from cc2586a to 328c878 Compare February 16, 2026 15:16
@rbeezer
Copy link
Collaborator

rbeezer commented Feb 16, 2026

OK, just one showstopper. Extant "stack integration" question has gone backwards. This needs a fix before I can merge.

  • The static version seems to have picked up a span element inside the m in the answer, with the result that there is nothing in the LaTeX output.

  • The HTML version says "The provided file does not contain valid XML". I have not chased that down. I'd suspect it is related, but have no reason to back that up.

I have about an hour into rearranging commits and testing. Please do not change any commits here. You can tell me (clearly) about a minor edit and I will do it, or add on a new commit (which I will cherry-pick into what I have going).

General comments in next message - none meant for action on this PR.

@rbeezer
Copy link
Collaborator

rbeezer commented Feb 16, 2026

Some general comments. I'll start more general and work my way into minor nit-picking. ;-)

  • Good job with the images - I'd have expected that to be more of a chore.
  • New exercises 3, 4 and 5. PDF shows "Answer." and no content. (Maybe the span problem above?) Unclear what is going on.
  • There's a whole lot of regex stuff going on here in the Python. We like XML so we don't have to do this. ;-) I hope a lot of this can be fixed as the server produces more PreTeXt code. In any event, what do you think about putting the STACK routines into their own file/module? (Yes, these comments probably apply to WeBWorK, which has just grown on us slowly over many years.)
  • There was a bit of stray whitespace in the Python - two blank lines with multiple spaces. I'm really careful about keeping this out of the code and avoiding the attendant problems down the line.
  • STACK is a good prefix for commits, and if they are just static-related we can say so in the message. I do not capitalize the first word after the colon. Very good to have a separate commit for the sample article additions, and it should be prefixed as such.
  • I do before/after testing with/without new material in the sample article. It helps me if the additions are in the last commit.

Yes, I keep saying I should write these up in The Guide...

Thanks for all your work on this. You knew it was going to be a big job, no? ;-)

@geoo89
Copy link
Contributor Author

geoo89 commented Feb 17, 2026

Hi Rob, thanks for your quick response!

I cannot reproduce any of these issues, the STACK questions build fine for me:

image

The STACK integration question static version the I get when running pretext generate stack looks like this:

<stack-static>
<statement><p>Find <me> \int {{\left(x-3\right)}^6} d{x}</me> <fillin characters="20" name="ans1"/> </p></statement>
<solution><p>We can either do this question by inspection (i.e. spot the answer) or in a more formal manner by using the substitution <me> u = ({x}-{3}).</me> Then, since <m>\frac{d}{d{x}}u=1</m> we have <me> \int {{\left(x-3\right)}^6} d{x} = \int u^{6} du = \frac{u^{7}}{7}+c = {\frac{{\left(x-3\right)}^7}{7}}+c.</me></p></solution>
<answer><p><m>\frac{{\left(x-3\right)}^7}{7}+c</m></p></answer>
</stack-static>

I do remember having the issue with tags inside the <m> at some point during development, possibly when I initially made the draft PR, but that should be fixed. I did a rebase and a force-push of this branch before I marked this PR ready for review. Can you make sure you have the latest version of this branch (last commit being 328c878)?

I also noticed that I didn't update the API URL for the sample article to https://stack-api.maths.ed.ac.uk (now that this official one is working), but the one we have in the sample article is working for me too.

@geoo89
Copy link
Contributor Author

geoo89 commented Feb 17, 2026

  • There's a whole lot of regex stuff going on here in the Python. We like XML so we don't have to do this. ;-) I hope a lot of this can be fixed as the server produces more PreTeXt code. In any event, what do you think about putting the STACK routines into their own file/module? (Yes, these comments probably apply to WeBWorK, which has just grown on us slowly over many years.)

The Regexes are not actually capturing XML elements, they are mostly to convert MathJax to PreText, and replace STACK-specific blocks (e.g. input fields, feedback fields) with their PreText equivalent. I do parse the HTML that is returned by the API using lxml to convert commonly used HTML tags.

  • STACK is a good prefix for commits, and if they are just static-related we can say so in the message. I do not capitalize the first word after the colon. Very good to have a separate commit for the sample article additions, and it should be prefixed as such.

Thanks, I'll keep that in mind for the future. Let me know if you want me to update the commit messages or if you're going ahead with that yourself.

  • I do before/after testing with/without new material in the sample article. It helps me if the additions are in the last commit.

As above, let me know if you want me to reorder the commits. I'll keep it in mind for the future.

@rbeezer
Copy link
Collaborator

rbeezer commented Feb 17, 2026

We cannot do development with the CLI - I thought I have made this clear. It lags the main repository, and it caches some results. Please do careful testing (before/after) with the pretext/pretext script.

I never have any problem picking up changes due to a forced push.

So I picked this up fresh, made no changes, and generated static versions. The suspect ,span> is there. Please reproduce this.

Did you happen to see #2787? Might it have some effect? More to say, but we need to get over this first.

@geoo89 geoo89 force-pushed the stack-static-improvements branch from 328c878 to 2fef0b4 Compare February 18, 2026 07:51
@geoo89
Copy link
Contributor Author

geoo89 commented Feb 18, 2026

Hi Rob, I rebased onto main to see if the issue is related to #2787, but no dice. (I updated the commit messages in the process and the STACK API URL in the sample article.)

The only issue I was able to reproduce was "The provided file does not contain valid XML" in the HTML version for the integration question. It seems like the API didn't like the namespace in that question (there was no namespace in the minimal STACK example, just the sample article). I'm surprised it still produced a sensible static version. I removed that namespace now.

Whatever I try, I'm unable to reproduce the <span> in the answer tags, nor the answers not displaying in the static outputs.

I made sure my working tree is clean. I'm running
pretext/pretext -c stack sample-article.xml -p publication.xml,
pretext/pretext -f latex-plus sample-article.xml -p publication.xml -c all, and
pretext/pretext -f html sample-article.xml -p publication.xml -c all -d output/html
respectively, all of which produce the intended results.

I'm using Python 3.10.12, with the following libraries:

annotated-types==0.7.0
autocommand==2.2.2
backports.tarfile==1.2.0
black==24.10.0
bottle==0.13.2
certifi==2025.1.31
charset-normalizer==3.4.1
cheroot==10.0.1
CherryPy==18.10.0
click==8.1.8
click-log==0.4.0
CodeChat==1.9.4
CodeChat_Server==0.2.25
coloraide==4.2.2
coverage==7.6.1
docutils==0.20.1
errorhandler==2.0.1
exceptiongroup==1.2.2
flake8==6.1.0
ghp-import==2.1.0
gitdb==4.0.12
GitPython==3.1.44
greenlet==3.1.1
idna==3.10
iniconfig==2.1.0
jaraco.collections==5.1.0
jaraco.context==6.0.1
jaraco.functools==4.1.0
jaraco.text==4.0.0
Jinja2==3.1.6
json-five==1.1.2
lxml==5.3.1
lxml-stubs==0.5.1
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mccabe==0.7.0
mdurl==0.1.2
more-itertools==10.5.0
mypy==1.14.1
mypy-extensions==1.0.0
packaging==24.2
pathspec==0.12.1
pdfCropMargins==1.0.9
pep8-naming==0.14.1
pillow==10.4.0
plasTeX==3.1
platformdirs==4.3.7
playwright==1.48.0
pluggy==1.5.0
portend==3.2.0
-e git+ssh://git@github.com/IDEMSInternational/pretext-cli.git@9b94881a3c647dc0f9ee8aaa0c73718d33562a44#egg=pretext
psutil==7.0.0
pycodestyle==2.11.1
pydantic==2.10.6
pydantic-xml==2.14.3
pydantic_core==2.27.2
pyee==12.0.0
pyflakes==3.1.0
Pygments==2.19.1
PyMuPDF==1.24.11
PyPDF2==2.5.0
pypng==0.20220715.0
pytest==7.4.4
pytest-console-scripts==1.4.1
pytest-cov==4.1.0
pytest-mock==3.14.0
python-dateutil==2.9.0.post0
qrcode==7.4.2
regex==2024.11.6
requests==2.32.3
rich==13.9.4
shellingham==1.5.4
single-version==1.6.0
six==1.17.0
sly==0.5
smmap==5.0.2
strictyaml==1.7.3
tempora==5.7.1
thrift==0.21.0
toml==0.10.2
tomli==2.2.1
typer==0.15.2
typing-inspection==0.4.0
typing_extensions==4.12.2
Unidecode==1.3.8
urllib3==2.2.3
watchdog==4.0.2
websockets==13.1
zc.lockfile==3.0.post1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments