PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
266 stars 208 forks source link

webwork_to_xml regex fails for static images via lighttpd #1135

Closed coltongrainger closed 5 years ago

coltongrainger commented 5 years ago

To pinpoint the issue for later reference. The regex

        graphics_pattern = re.compile(r'<image.*?source="([^\.]*)\.([^"]*)"')

matches both

but the iterator in line 627 of mbx, under the definition of webwork_to_xml, relies on stripping a file extension via

            ww_basename = match.group(1)
            file_extension = '.' + match.group(2)

eventually raises raise ValueError(os.path.join(dest_dir, ptx_filename) + root_cause).

ValueError: /home/colton/fy/20/mwe/output/webwork-extraction/webwork-3-image-1.0.0.1:8080/wwtmp/anonymous//gif/d911f729-b144-3e2c-877b-40969fbbb6da___64d25fc4-b24a-3bcc-8e16-0cab02808ecf.png[Errno 2] No such file or directory: u'/home/colton/fy/20/mwe/output/webwork-extraction/webwork-3-image-1.0.0.1:8080/wwtmp/anonymous//gif/d911f729-b144-3e2c-877b-40969fbbb6da___64d25fc4-b24a-3bcc-8e16-0cab02808ecf.png'

Minimal working example

$ tree
.
├── Makefile
├── Makefile.paths
├── output
└── src
    └── mini.xml

Makefile as follows.

# MAINDIR = /Users/justice/Documents/github/pretext-basics-reference
MAINDIR = /home/colton/fy/20/mwe

# PreTeXt distribution root
# Example:
# PTX = /Users/justice/Documents/github/mathbook
PTX = /home/colton/fy/20/mathbook

# Products are built in subdirectories
# of an "output" directory
# Example:
OUTPUT = $(MAINDIR)/output

# Jing-Trang for RELAX-NG schema validation
# Example:
# JINGTRANG = /Users/justice/Documents/github/jing-trang/build
JINGTRANG = /home/colton/fy/20/jing-trang

# These are executables to helper applications
# Provide as much of a path as is needed

# LaTeX engine, executable
# xelatex is preferable, but pdflatex is another option
ENGINE = xelatex

# Text file viewer (eg, DTD errors)
# "more" or "less" are likely system utilities
PAGER = less

# HTML viewer  (eg "open -a firefox", "open -a safari", on Mac)
HTMLVIEWER = firefox

# These paths are subdirectories of
# the PreTeXt distribution
# PTXUSR is where extension files get copied
# so relative paths work properly
PTXXSL = $(PTX)/xsl
PTXUSR = $(PTX)/user

MAINFILE = $(MAINDIR)/src/mini.xml
IMAGESSRC = $(MAINDIR)/src/images

# These paths are subdirectories of
# the scratch directory
HTMLOUT    = $(OUTPUT)/html
PDFOUT     = $(OUTPUT)/pdf
EPUBOUT    = $(OUTPUT)/epub
WWOUT      = $(OUTPUT)/webwork-extraction

# Some aspects of producing these examples require a WeBWorK server.
# We default to using the AIM-provided development server.
SERVER = "(http://127.0.0.1,anonymous,anonymous,anonymous,anonymous)"

################
#Targets for make
################

#  Extract webwork problems into a single XML file called
#  webwork-extraction.xml which holds multiple versions of each problem.
#  Also locally store images from the WeBWorK server.

mini-extraction:
    install -d $(WWOUT)
    -rm $(WWOUT)/webwork-extraction.xml
    PYTHONWARNINGS=module $(PTX)/script/mbx -c webwork -d $(WWOUT) -s $(SERVER) $(MAINFILE)

mini-merge:
    cd $(WWOUT); \
    xsltproc -xinclude  --stringparam webwork.extraction $(WWOUT)/webwork-extraction.xml $(PTXXSL)/pretext-merge.xsl $(MAINFILE) > mini-merge.ptx

# Generate HTML output
# Output is:  $(HTMLOUT)/${MAINFILE%*.}.html
html: mini-merge
    install -d $(OUTPUT)
    install -d $(HTMLOUT)
    -rm -rf $(HTMLOUT)/knowl
    -rm $(HTMLOUT)/*.html
    -rm -rf $(HTMLOUT)/images
    install -d $(HTMLOUT)/knowl
    cp -a $(IMAGESSRC) $(HTMLOUT)
    cd $(HTMLOUT); \
    xsltproc -xinclude -stringparam numbering.theorems.level 1 -stringparam numbering.projects.level 1 -stringparam numbering.equations.level 1 -stringparam html.knowl.exercise.inline no $(PTXXSL)/mathbook-html.xsl $(WWOUT)/mini-merge.ptx

# make all the image files in svg format
images: mini-merge
    install -d $(OUTPUT)
    install -d $(IMAGESOUT)
    -rm $(IMAGESOUT)/*.svg
    $(PTX)/script/mbx -c latex-image -f all -d $(IMAGESOUT) $(OUTPUT)/mini-merge.ptx

preview:
    cd $(HTMLOUT); \
    $(HTMLVIEWER) index.html

# Generate PDF output by first producing LaTeX and then compiling with
# ENGINE.
# Output is: $(PDFOUT)/${MAINFILE%*.}.pdf
pdf: mini-merge
    install -d $(OUTPUT)
    install -d $(PDFOUT)
    install -d $(PDFOUT)/images
    -rm $(PDFOUT)/*.*
    -rm $(PDFOUT)/images/*
    -cp -a $(WWOUT)/*.png $(PDFOUT)/images
    cp -a $(IMAGESSRC) $(PDFOUT)
    cd $(PDFOUT); \
    xsltproc -o ${MAINFILE%*.}.tex -xinclude -stringparam numbering.theorems.level 1 -stringparam numbering.projects.level 1 -stringparam numbering.equations.level 1 $(PTXXSL)/mathbook-latex.xsl $(WWOUT)/mini-merge.ptx; \
    $(ENGINE) ${MAINFILE%*.}; \
    $(ENGINE) ${MAINFILE%*.}

###########
# Utilities
###########

# Verify Source integrity
#   Leaves "schema_errors.txt" in OUTPUT
check:
    install -d $(OUTPUT)
    -rm $(OUTPUT)/schema_errors.txt
    -java -classpath $(JINGTRANG) -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration -jar $(JINGTRANG)/jing.jar $(PTX)/schema/pretext.rng $(MAINFILE) > $(OUTPUT)/schema_errors.txt
    xsltproc --xinclude $(PTX)/schema/pretext-schematron.xsl $(MAINFILE) >> $(OUTPUT)/schema_errors.txt
    $(PAGER) $(OUTPUT)/schema_errors.txt

Document to compile.

<?xml version="1.0" encoding="UTF-8" ?>
<pretext xmlns:xi="http://www.w3.org/2001/XInclude">
    <article xml:id="webwork-mini">
        <title><webwork /> Minimal Example</title>
        <frontmatter>
            <titlepage>
                <author>
                    <personname>Jane Doe</personname>
                </author>
            </titlepage>
        </frontmatter>
        <section>
            <title><webwork /> Minimal Section</title>
                <exercise>
                  <title>Problem with Static Image</title>
                      <webwork source="Library/CollegeOfIdaho/setAlgebra_02_04_PointSlopeFormofLine/24IntAlg_14_LinearFunction.pg" />
                </exercise>
        </section>
    </article>
</pretext>
coltongrainger commented 5 years ago

Provided that I chance the server to https://webwork-ptx.aimath.org/, the regex functions as expected, which allows one to properly name static images.

Since I'd like images with webwork problems, I'll take a closed look this weekend.

coltongrainger commented 5 years ago

Here's a workaround for me: just disable lighttpd and keep the traditional image directories under the WebWork server.

[Disabling Optional B (lighttpd) for a single course](http://webwork.maa.org/wiki/Installation_Manual_for_2.13_on_Ubuntu_18.04].

coltongrainger commented 5 years ago

Another workaround is just to use https://webwork-ptx.aimath.org. I'm satisfied.

coltongrainger commented 5 years ago

I mean, it's my own local server. Of course I don't need lighttpd for compiling.

# Do not use lightppd (port 8080) for this course
$webworkURLs{htdocs_temp}   = '/wwtmp';
$courseURLs{html_temp}   = "/wwtmp/$courseName";
$webworkURLs{equationCache} = "$webworkURLs{htdocs_temp}/equations";
$webworkURLs{MathJax}       = "$webworkURLs{htdocs}/mathjax/MathJax.js?config=TeX-MML-AM_HTMLorMML-full";
rbeezer commented 5 years ago

If there is anything useful you'd like to see added to the documentation, feel free to make a new issue, or re-open this one. Thanks for your interest in PreTeXt + WeBWorK.

On 7/1/19 11:02 PM, Colton Grainger wrote:

Another workaround is just to use |https://webwork-ptx.aimath.org|. I'm satisfied.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rbeezer/mathbook/issues/1135?email_source=notifications&email_token=AAOLM4UFVP4YMWXTCCMOOWLP5LVOFA5CNFSM4H4YDCS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZAFB3Y#issuecomment-507531503, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOLM4UEVTT22XOJNLZWJG3P5LVOFANCNFSM4H4YDCSQ.

Alex-Jordan commented 5 years ago

Thanks for the detailed description of the regex issue. I will make an issue from that and return to see about making it better at some point. It sounds like for now it is not urgent, but it also sounds like better quality regex would be good here.