5.6.3. B2Tools#

class B2Tools.b2latex.DefineColourList[source]#

Bases: B2Tools.b2latex.LatexObject

Defines the colourlist latex-command, which draws a bargraph with relative fractions indicated by colours using tikz. After including this object in you latex code the command bargraph is available. You should include only one of these objects in your latex code.

colours = ['red', 'green', 'blue', 'orange', 'cyan', 'purple']#

6 default colours used for the bargraph

class B2Tools.b2latex.Graphics[source]#

Bases: B2Tools.b2latex.LatexObject

Includes a series of image files into your latex code and centers them.

add(filename, width=0.7)[source]#

Include a image file.

Parameters
  • filename – containing the image

  • width – texwidth argument of includegraphics

finish()[source]#

Ends centered environment

class B2Tools.b2latex.Itemize[source]#

Bases: B2Tools.b2latex.LatexObject

Creates a itemized list in latex.

add(item)[source]#

Adds another item.

Parameters

item – string or object with implicit string conversion used as item

amount#

number of items

finish()[source]#

Finishes the generation of latex-code.

class B2Tools.b2latex.LatexFile[source]#

Bases: B2Tools.b2latex.LatexObject

Convinience class implementing += operator, can be used instead of raw LatexObject to collect all the latex code in your project which should go into a common file.

add(text='')[source]#

Adds an object to the output

Parameters

text – string or object with implicit string conversion (like LatexObject)

class B2Tools.b2latex.LatexObject[source]#

Bases: object

Common base class of all Latex Wrapper objects

add()[source]#

Add latex-code to the output string. This method is usually overriden in the subclasses

finish()[source]#

Finishes the generation of latex-code. E.g. adds end latex-commands This method is usually overriden in the subclasses

output#

Stores the outputted latex-code

save(filename, compile=False)[source]#

Saves the latex-code into a file, adds preamble and end of document, and compiles the code if requested.

Parameters
  • filename – latex-code is stored in this file, should end on .tex

  • compile – compile the .tex file using pdflatex into a .pdf file

class B2Tools.b2latex.Listing(language='XML')[source]#

Bases: B2Tools.b2latex.LatexObject

Used for wrapping code in a listing environment

add(text='')[source]#

Adds code to the output

Parameters

code – which is wrapped in the listing environment

finish(**kwargs)[source]#

Finish the generation of the lsiting environment

class B2Tools.b2latex.LongTable(columnspecs, caption, format_string, head)[source]#

Bases: B2Tools.b2latex.LatexObject

Creates a longtable in latex. A longtable can span multiple pages and is automatically wrapped.

add(*args, **kwargs)[source]#

Add a new row to the longtable by generating the row using the format_string given in init and the provided dictionary.

Parameters
  • args – positional arguments used to generate the row using the python-style format string.

  • kwargs – dictionary used to generate the row using the python-style format-string.

finish(tail='')[source]#

Adds optional tail of the table, ends longtable and centered environment.

Parameters

tail – optional tail, like head but at the bottom of the table.

format_string#

python-style format-string used to generate a new row out of a given dictionary.

class B2Tools.b2latex.Section(name)[source]#

Bases: B2Tools.b2latex.LatexObject

Adds a new section to your latex code with some additional commands to force a pagebreak and add a barrier for figure objects.

class B2Tools.b2latex.String(text='')[source]#

Bases: B2Tools.b2latex.LatexObject

Used for wrapping conventionel text into latex-code. Has to possibility to handle python-style format-placeholders

add(text='')[source]#

Adds an object to the output, can contain python-placeholders

Parameters

text – string or object with implicit string conversion (like LatexObject)

finish(**kwargs)[source]#

Finish the generation of the string by replacing possible placehholders with the given dictionary

Parameters

kwargs – dictionary used to replace placeholders

class B2Tools.b2latex.SubSection(name)[source]#

Bases: B2Tools.b2latex.LatexObject

Adds a new subsection to your latex code.

class B2Tools.b2latex.SubSubSection(name)[source]#

Bases: B2Tools.b2latex.LatexObject

Adds a new subsubsection to your latex code.

class B2Tools.b2latex.TitlePage(title, authors, abstract, add_table_of_contents=True, clearpage=True)[source]#

Bases: B2Tools.b2latex.LatexObject

Creates a latex title-page and optionally abstract and table-of-contents. You should include only one of these objects in your latex code.

class B2Tools.format.AttrDict(content)[source]#

Bases: object

Simple wrapper class to allow accessing dictionary elements via attribute access

class B2Tools.format.DefaultValueFormatter[source]#

Bases: string.Formatter

Custom formatter class which allows to substitute a missing value with a default value

format_field(value, spec)[source]#

Format a single field:

  • if the field is None and we have a := specification we replace the field with the default value and change the spec to ‘s’

  • if the value is None we replace it with an empty string

then we just run the normal formatter …

get_field(field_name, args, kwargs)[source]#

Try to get the field as usual but in case we cannot find it because it either doesn’t exist or it doesn’t have the correct attribute/item we just return None

B2Tools.format.decayDescriptor(decay_string)[source]#

Prettifies the given decay string by using latex-symbols instead of plain-text

Parameters

decay_string – string containing a decay descriptor

Returns

string latex version of the decay descriptor

B2Tools.format.duration(seconds)[source]#

Converts a duration given in seconds into a nice latex-style duration string

Parameters

seconds – duration in seconds

Returns

string describing a duration in a natural format

B2Tools.format.format_filename(template, filename, metadata_json)[source]#

Format a file name as described in BELLE2-NOTE-TE-2017-012

Parameters
  • template (str) – the format string

  • filename (str) – the name of the file

  • metadata_json (str) – a string representation of the file metadata json

Returns

a string with the formatted file name

B2Tools.format.string(some_string)[source]#

Used to escape user strings for LaTex.

Parameters

some_string – which is escaped

Returns

string escaped version of some_string

B2Tools.format.variable(variable_string)[source]#

Adds hyphenations after brackets, and for common variables.

Parameters

variable_string – variable name

Returns

string with hyphenation hints for latex