Stack static improvements#2779
Conversation
1edc49f to
cc2586a
Compare
cc2586a to
328c878
Compare
|
OK, just one showstopper. Extant "stack integration" question has gone backwards. This needs a fix before I can merge.
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. |
|
Some general comments. I'll start more general and work my way into minor nit-picking. ;-)
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? ;-) |
|
Hi Rob, thanks for your quick response! I cannot reproduce any of these issues, the STACK questions build fine for me:
The STACK integration question static version the I get when running I do remember having the issue with tags inside the 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. |
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.
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.
As above, let me know if you want me to reorder the commits. I'll keep it in mind for the future. |
|
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 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 Did you happen to see #2787? Might it have some effect? More to say, but we need to get over this first. |
328c878 to
2fef0b4
Compare
|
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 I made sure my working tree is clean. I'm running I'm using Python 3.10.12, with the following libraries: |
|
FWIW, I checked out this PR locally, launched a local STACK API based on the current STACK dev branch (Demo server didn't work due to CORS restrictions), ran the commands @geoo89 posted in the previous post, and it worked smoothly for me (both HTML and PDF, all 5 STACK problems). See screenshot.
|
|
Thanks, @anst-i . I am tardy on this one, since I am a bit baffled. It was close to the top of my list already - likely I can take another look early next week. |
|
With the last push on Feb 18 I fixed the one issue that I was able to reproduce, but I also changed the URL of the STACK API to use the official one from the University of Edinburgh (which is slightly ahead of the deployment that the examples referenced before). So there's a small chance that things magically got fixed for you as well through this. |
|
Change in plans, stalled out on today's work. So...
diff --git a/../sold/stack-integration.ptx b/./stack-integration.ptx
index 2e6fd33..50f8a1a 100644
--- a/../sold/stack-integration.ptx
+++ b/./stack-integration.ptx
@@ -1,6 +1,5 @@
<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>
+ <answer><p><m><span>\frac{{\left(x-3\right)}^7}{7}+c</span></m></p></answer>
</stack-static>
\ No newline at end of file
|
|
I see the So asked Claude Code to track it down. Its analysis will be the next comment. Maybe it is trash, maybe it is helpful. I'm sort of flying blind at this point. |
|
The bug is in The At line 2877, The The result is Root cause in one sentence: Analysis by Claude Sonnet 4.6 as review assistant for @rbeezer. |
|
Thank you for the careful explanation @rbeezer , I am completely new to PreTeXt and I'm grateful for your patience. I have checked my local Regarding the explanation by the LLM, I am a bit puzzled: Line 2877 of the commit does not contain I have also tried running the relevant Python code in an isolated script, and for me If we can't find out why this function works differently on your machine, maybe we can change line 2794 to: Attached is a minimal code sample, containing the changed line in |
|
Thanks for taking a closer look, both of you. Claude's suggestion is helpful, I've managed to track down the issue: In lxml 5.3.1, On my system I had lxml 5.3.1 installed while I assume you've had some version of lxml >=6. The pypi pretext package appears to require There appears to be a method |
|
Hi Rob, I pushed a fix and tried to keep it as simple as possible. The downside of this particular implementation is that we may have nested
While STACK users will have to vet their questions to ensure that they work in PreText, I'd like to make it as easy as possible, so I'd rather have this supported. If you prefer, I can write code that will parse the text more carefully and wrap anything that doesn't have a parent |
|
Yes, I have lxml 6.0.2. Next thing I might have done was to check your previous list of version numbers. Glad we have an explanation. (Maybe requirements.txt needs an upadate...)
Well, it should if you do schema validation (while the schema is known to be a bit imperfect). The conversions do not test for legal PreTeXt. So lack of complaints, and especially simply getting ppretty output, do not equate to having quality source. Consciously making nested #p sounds like a dangerous idea. The pre-processor could have a mode that "cleans up" whatever comes back from the server - a #p with an ancestor #p could be scrubbed. Or maybe do that with lxml? I've merged this, but would like to see the situation improve. And I really do not understand why the LaTeX does not end up with some extra vertical space due to the double-p? Images: I think I said before that it is very good you have this working. A PDF version will of course work well for LaTeX/PDF. But we have other static formats. For example, we must have a PNG image for EPUB, or the build breaks. So those need to be generated - should be plenty of examples in the Python for how to do this (i.e. which tools). Mimic what is there or have AI mimic it. Note that we do not regenerate things like this, they need to go into the "generated" directory and are committed to the repository. I've done that here before merging, but it should be part of the drill when you add new examples. I think that is most everything. Website examples updated. Holler if there are unanswered questions. |


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