mosra / m.css

A no-nonsense, no-JavaScript CSS framework, site and documentation theme for content-oriented websites
https://mcss.mosra.cz
MIT License
399 stars 88 forks source link

Incompatible preamble (dvisgm 2.12) #210

Closed cbritopacheco closed 2 years ago

cbritopacheco commented 2 years ago

Environment

OS macOS Big Sur
Python 3.8.12
m.css 9385194fa3392a7162e7535cc2478814e382ff8a
dvisgm 2.12_2 (macports build)

Problem

An assertion is triggered on my machine when trying to build the documentation with any math. This is due to an incompatibility in the dvisgm preamble. The exception stack is this:

Traceback (most recent call last):
  File "../../third-party/m.css/documentation/doxygen.py", line 3859, in <module>
    run(state, templates=os.path.abspath(args.templates), wildcard=args.wildcard, index_pages=args.index_pages, search_merge_subtrees=not args.search_no_subtree_merging, search_add_lookahead_barriers=not args.search_no_lookahead_barriers, search_merge_prefixes=not args.search_no_prefix_merging)
  File "../../third-party/m.css/documentation/doxygen.py", line 3716, in run
    parsed = parse_xml(state, file)
  File "../../third-party/m.css/documentation/doxygen.py", line 2845, in parse_xml
    func = parse_func(state, memberdef)
  File "../../third-party/m.css/documentation/doxygen.py", line 1926, in parse_func
    func.description, templates, params, func.return_value, func.return_values, func.exceptions, search_keywords, func.deprecated, func.since = parse_func_desc(state, element)
  File "../../third-party/m.css/documentation/doxygen.py", line 1756, in parse_func_desc
    parsed = parse_desc_internal(state, element.find('detaileddescription'))
  File "../../third-party/m.css/documentation/doxygen.py", line 690, in parse_desc_internal
    parsed = parse_desc_internal(state, i,
  File "../../third-party/m.css/documentation/doxygen.py", line 1289, in parse_desc_internal
    out.parsed += latex2svgextra.patch(i.text, svg, depth, attribs)
  File "../../third-party/m.css/documentation/../plugins/latex2svgextra.py", line 196, in patch
    assert found
AssertionError

The actual problem is the following. dvisgm has made a miniscule change in specifying its version:

<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.12 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='33.921937pt' height='14.94396pt' viewBox='0 -8.966376 27.137549 11.955168'>

Now instead of 2.12.x we have 2.12.

Proposed fix/workaround

The file to be patched is latex2svgextra.py. We can simply modify _patch26_src to incorporate the lack of the subversion number.

_patch26_src = re.compile(r"""<\?xml version='1\.0' encoding='UTF-8'\?>
<!-- This file was generated by dvisvgm \d+\.\d+(\.\d+)? -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='(?P<width>[^']+)pt' height='(?P<height>[^']+)pt' viewBox='(?P<viewBox>[^']+)'>
""")

Alternatively we could also define a new variable _patch212_src with the above declaration and add the following lines of code:

    svg, found = _patch_src.subn(repl, svg)
    if not found:
        svg, found = _patch26_src.subn(repl, svg)
        assert found
        if not found:
            svg, found = _patch212_src.subn(repl, svg)
            assert found

Maybe throwing an exception expliciting what is going on would be useful.

The above fix allows me to build the documentation without any problems.

mosra commented 2 years ago

Fixed with a variant of #211, commited as f05937f57f17656772aff0315677c15447d05f4d.

With this closed, I'm finally back to just a single page of issues again. Yay!