Use \seqsplit for DOIs to avoid awkward spacing

This commit is contained in:
RunasSudo 2021-02-22 19:03:04 +11:00
parent afc151913f
commit 55cf6d77d6
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -14,9 +14,11 @@ def setup(app):
app.add_role('subref', SubRefRole())
app.add_role('msubref', MSubRefRole())
#app.add_source_parser(PORSTParser, override=True)
app.add_source_parser(PORSTParser, override=True)
# ===================================================================
# HTML Builder
# ===================================================================
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.environment.adapters.toctree import TocTree
@ -85,7 +87,9 @@ def _TocTree_resolve(self, *args, **kwargs):
return result
TocTree.resolve = _TocTree_resolve
# ===================================================================
# LaTeX Builder
# ===================================================================
from sphinx.builders.latex import LaTeXBuilder
from sphinx.writers.latex import LaTeXTranslator
@ -114,6 +118,8 @@ class POLaTeXTranslator(LaTeXTranslator):
self.body.append(r'{{\small\bfseries\sffamily[{0}]}} '.format(self.paragraph_num))
def visit_reference(self, node):
uri = node.get('refuri', '')
if 'po_mref' in node.attributes:
# Force page reference
self.builder.config.latex_show_pagerefs = True
@ -122,10 +128,35 @@ class POLaTeXTranslator(LaTeXTranslator):
else:
super().visit_reference(node)
if '://doi.org/' in uri:
# Fix formatting of DOI references
self.body.append('\\seqsplit{')
def depart_reference(self, node):
uri = node.get('refuri', '')
if '://doi.org/' in uri:
# Fix formatting of DOI references
self.body.append('}')
super().depart_reference(node)
class POLaTeXBuilder(LaTeXBuilder):
default_translator_class = POLaTeXTranslator
# Don't escape "-"
import sphinx.util.texescape
sphinx.util.texescape.ascii_tex_replacements.remove(('-', r'\sphinxhyphen{}'))
__texescape_init = sphinx.util.texescape.init
def _texescape_init():
__texescape_init()
del sphinx.util.texescape._tex_escape_map_without_unicode[ord('-')]
sphinx.util.texescape.init = _texescape_init
# ===================================================================
# Epub3 Builder
# ===================================================================
from sphinx.builders.epub3 import Epub3Builder
@ -142,7 +173,9 @@ class POEpub3Builder(Epub3Builder):
'text': 'Index'
})
# ===================================================================
# Referencing roles
# ===================================================================
from sphinx.roles import XRefRole
@ -248,14 +281,14 @@ def _StandardDomain_resolve_doc_xref(self, env, fromdocname, builder, typ, targe
return result
StandardDomain._resolve_doc_xref = _StandardDomain_resolve_doc_xref
# RST Parser
# ===================================================================
# RST Parser (unused)
# ===================================================================
from sphinx.parsers import RSTParser
class PORSTParser(RSTParser):
def parse(self, inputstring, document):
super().parse(inputstring, document)
pass
# Verify footnotes
print(document)
#def parse(self, inputstring, document):
# super().parse(inputstring, document)