1. luensdorf
  2. simpy-example-annotation

Commits

Ontje Lünsdorf  committed ee63368

Added LaTeX output handling. Removed custom css and use pygments styles instead.

  • Participants
  • Parent commits 2c2098c
  • Branches default

Comments (0)

Files changed (5)

File docs/ext/annotate.py

View file
 def visit_annotation_html(self, node):
     # Use pygments generated css classes to highlight annotations in HTML
     # ouput.
-    self.body.append('<span class="highlight c-Annotation">')
+    self.body.append('<span class="highlight"><span class="c-Annotation">')
 
 
 def depart_annotation_html(self, node):
-    self.body.append('</span>')
+    self.body.append('</span></span>')
+
+
+def visit_annotation_latex(self, node):
+    # Use pygments generated LaTeX commands to highlight annotations.
+
+    # Use a raisebox to lift annotation box a little bit, so that it appears
+    # vertically centered in line.
+    self.body.append(
+            '\\raisebox{0.2ex}[0pt][0pt]{\\tt\\tiny\\PYG{c+cAnnotation}{')
+
+
+def depart_annotation_latex(self, node):
+    self.body.append('}}')
 
 
 def setup(app):
     lexers['python'].add_filter(annotation_filter())
 
     # Add node and role for annotations.
-    app.add_node(annotation, html=(visit_annotation_html,
-        depart_annotation_html))
+    app.add_node(annotation,
+            html=(visit_annotation_html, depart_annotation_html),
+            latex=(visit_annotation_latex, depart_annotation_latex),
+    )
     app.add_role('an', annotation_role)
-
-    # Add custom stylesheet for highlighting annotations.
-    app.add_stylesheet('annotation.css')

File docs/ext/style.py

View file
+# coding=utf-8
+
+from pygments.token import Comment
+from sphinx.highlighting import SphinxStyle
+
+class SimpyStyle(SphinxStyle):
+    styles = SphinxStyle.styles
+    styles.update({
+        Comment.Annotation: ('noinherit bg:#ffff00 border:#ff8000 nobold '
+            'noitalic #000000')
+    })

File docs/source/Tutorials/TheBank.rst

View file
 name at :an:`7`. This completes the declaration of the ``Customer`` class.
 
 The call ``initialize()`` at :an:`9` sets up the simulation
-system ready to receive ``activate`` calls. At :an:``, we create
+system ready to receive ``activate`` calls. At :an:`10`, we create
 a customer, ``c``, with name ``Klaus``. All SimPy Processes have a
-``name`` attribute. We ``activate`` ``Klaus`` at :an:`10`
+``name`` attribute. We ``activate`` ``Klaus`` at :an:`11`
 specifying the object (``c``) to be activated, the call of the action
 routine (``c.visit(timeInBank = 10.0)``) and that it is to be activated
 at time 5 (``at = 5.0``). This will activate

File docs/source/_static/annotation.css

-/* comment annotation */
-.c-Annotation {
-    background-color: yellow;
-    border: 1px solid orange;
-    border-radius: 0.4em;
-    padding-left: 0.2em;
-    padding-right: 0.2em;
-    margin-right: 0.1em; /* necessary because of shadows */
-    box-shadow:0.1em 0.1em 0.1em #888;
-    color: #000000;
-    font-family: monospace;
-    font-style: bold;
-}

File docs/source/conf.py

View file
 #show_authors = False
 
 # The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
+pygments_style = 'ext.style.SimpyStyle'
 
 # A list of ignored prefixes for module index sorting.
 #modindex_common_prefix = []