rhopfer / sphinx-numbered-blocks

Extension for sphinx to create custom numbered environments.
MIT License
1 stars 4 forks source link

References not working in LaTeX #7

Open AdamSmasherDerby opened 3 months ago

AdamSmasherDerby commented 3 months ago

Good morning - it's been a few years! I've started trying to add some references without our document, and the links aren't working in the LaTeX output. I suspect that this just hasn't been implemented for LaTeX, but before I start digging, I was wondering if you had any thoughts on this?

Minimal code:

conf.py numbered_blocks = [ {'name': 'scenario', 'label-format': 'Scenario C%s', 'reference-format': 'Scenario C%s'}, ]

file.rst

See :scenario-ref:`a-scenario`

.. scenario::
   :name: a-scenario

When compiled, the LaTeX is simply empty after the word "See"

At a VERY cursory inspection of the code, my first impulse is that something needs to be added around line 398:

        html = '<a href="%s">%s</a>' % (link, label) 
        ref.replace_self(nodes.raw(html, html, format='html'))

that specifically deals with LaTeX, but I haven't dug into the guts of Sphinx since the last time we talked.

Any thoughts would be appreciated - I can work on it at some point, but I don't want to duplicate effort, or find out I've missed something obvious.

AdamSmasherDerby commented 3 months ago

Update: I have confirmed that this seems just not to have been implemented for LaTeX, and have gotten the TEXT to appear by replacing the two lines above with:

        if app.builder.name == 'html':
            html = '<a href="%s">%s</a>' % (link, label)
            ref.replace_self(nodes.raw(html, html, format='html'))
        elif app.builder.name == 'latex':
            latex = '\\hyperref[\detokenize{' + link + '}]{' + label + '}'
            ref.replace_self(nodes.raw(latex,latex,format='latex'))
            pass
        else:
            pass

I know doing explicit builder checks within the body of the extension isn't a best practice, but it's working.

However, I haven't managed to figure out how to apply the correct LABEL when the titles are generated, so the link doesn't actually POINT to anything.