1212from docutils .nodes import Node
1313from sphinx .writers .latex import LaTeXTranslator
1414
15- CR = '\n '
16- latex_admonition_start = CR + '\\ begin{sphinxadmonition}{note}'
17- latex_admonition_end = '\\ end{sphinxadmonition}' + CR
15+ CR = "\n "
16+ latex_admonition_start = CR + "\\ begin{sphinxadmonition}{note}"
17+ latex_admonition_end = "\\ end{sphinxadmonition}" + CR
18+
1819
1920class proof_node (nodes .Admonition , nodes .Element ):
2021 pass
@@ -30,7 +31,7 @@ class unenumerable_node(nodes.Admonition, nodes.Element):
3031
3132def visit_enumerable_node (self , node : Node ) -> None :
3233 if isinstance (self , LaTeXTranslator ):
33- self .body .append (latex_admonition )
34+ self .body .append (latex_admonition_start )
3435 else :
3536 self .body .append (self .starttag (node , "div" , CLASS = "admonition" ))
3637
@@ -39,7 +40,7 @@ def depart_enumerable_node(self, node: Node) -> None:
3940 typ = node .attributes .get ("type" , "" )
4041 if isinstance (self , LaTeXTranslator ):
4142 number = get_node_number_latex (self , node )
42- idx = list_rindex (self .body ,latex_admonition ) + 2
43+ idx = list_rindex (self .body , latex_admonition_start ) + 2
4344 self .body .insert (idx , f"{ typ .title ()} { number } " )
4445 self .body .append (latex_admonition_end )
4546 else :
@@ -52,7 +53,7 @@ def depart_enumerable_node(self, node: Node) -> None:
5253
5354def visit_unenumerable_node (self , node : Node ) -> None :
5455 if isinstance (self , LaTeXTranslator ):
55- self .body .append (latex_admonition )
56+ self .body .append (latex_admonition_start )
5657 else :
5758 self .body .append (self .starttag (node , "div" , CLASS = "admonition" ))
5859
@@ -61,14 +62,14 @@ def depart_unenumerable_node(self, node: Node) -> None:
6162 typ = node .attributes .get ("type" , "" )
6263 title = node .attributes .get ("title" , "" )
6364 if isinstance (self , LaTeXTranslator ):
64- idx = list_rindex (self .body ,latex_admonition ) + 2
65+ idx = list_rindex (self .body , latex_admonition_start ) + 2
6566 self .body .insert (idx , f"{ typ .title ()} " )
6667 self .body .append (latex_admonition_end )
6768 else :
6869 if title == "" :
69- idx = list_rindex (self .body ,'<p class="admonition-title">' ) + 1
70+ idx = list_rindex (self .body , '<p class="admonition-title">' ) + 1
7071 else :
71- idx = list_rindex (self .body ,title )
72+ idx = list_rindex (self .body , title )
7273 element = f"<span>{ typ .title ()} </span>"
7374 self .body .insert (idx , element )
7475 self .body .append ("</div>" )
@@ -81,7 +82,8 @@ def visit_proof_node(self, node: Node) -> None:
8182def depart_proof_node (self , node : Node ) -> None :
8283 pass
8384
84- def find_parent (env , node , parent_tag ):
85+
86+ def find_parent (env , node , parent_tag ):
8587 """Find the nearest parent node with the given tagname."""
8688 while True :
8789 node = node .parent
@@ -93,32 +95,37 @@ def find_parent(env, node , parent_tag):
9395 and env .titles [node .attributes ["docname" ]].astext ().lower ()
9496 in node .attributes ["names" ]
9597 ):
96- return node .attributes [' docname' ]
98+ return node .attributes [" docname" ]
9799
98100 if node .tagname == parent_tag :
99- return node .attributes [' docname' ]
101+ return node .attributes [" docname" ]
100102
101103 return None
102104
105+
103106def get_node_number (self : HTMLTranslator , node : Node ) -> str :
104107 """Get the number for the directive node for HTML."""
105108 key = "proof"
106109 ids = node .attributes .get ("ids" , [])[0 ]
107110 number = self .builder .fignumbers .get (key , {}).get (ids , ())
108111 return "." .join (map (str , number ))
109112
113+
110114def get_node_number_latex (self : LaTeXTranslator , node : Node ) -> str :
111115 """Get the number for the directive node for LaTeX."""
112116 key = "proof"
113117 docname = find_parent (self .builder .env , node , "section" )
114118 ids = node .attributes .get ("ids" , [])[0 ]
115- fignumbers = self .builder .env .toc_fignumbers .get (docname , {}) # Latex does not have builder.fignumbers
119+ fignumbers = self .builder .env .toc_fignumbers .get (
120+ docname , {}
121+ ) # Latex does not have builder.fignumbers
116122 number = fignumbers .get (key , {}).get (ids , ())
117123 return "." .join (map (str , number ))
118124
125+
119126def list_rindex (li , x ) -> int :
120127 """Getting the last occurence of an item in a list."""
121128 for i in reversed (range (len (li ))):
122129 if li [i ] == x :
123130 return i
124- raise ValueError ("{} is not in list" .format (x ))
131+ raise ValueError ("{} is not in list" .format (x ))
0 commit comments