Belle II Software development
LongTable Class Reference
Inheritance diagram for LongTable:
LatexObject

Public Member Functions

 __init__ (self, columnspecs, caption, format_string, head)
 
 add (self, *args, **kwargs)
 
 finish (self, tail='')
 
 __str__ (self)
 
 save (self, filename, compile=False)
 

Public Attributes

 format_string = format_string
 python-style format-string used to generate a new row out of a given dictionary.
 
str output = ''
 Stores the outputted latex-code.
 

Detailed Description

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

Definition at line 377 of file b2latex.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
columnspecs,
caption,
format_string,
head )
Calls super-class init, begins centered environment and longtable environment. Defines caption and head of the table. @param columnspecs of the longtable, something like: rclp{7cm} 4 columns, right-center-left aligned and one paragraph column with a width of 7cm @param caption string or object with implicit string conversion used as caption. @param format_string python-style format-string used to generate a new row out of a given dictionary. @param head of the table

Definition at line 383 of file b2latex.py.

383 def __init__(self, columnspecs, caption, format_string, head):
384 """
385 Calls super-class init, begins centered environment and longtable environment.
386 Defines caption and head of the table.
387 @param columnspecs of the longtable, something like:
388 rclp{7cm} 4 columns, right-center-left aligned and one paragraph column with a width of 7cm
389 @param caption string or object with implicit string conversion used as caption.
390 @param format_string python-style format-string used to generate a new row out of a given dictionary.
391 @param head of the table
392 """
393 super().__init__()
394 self.output += r"\begin{center}" + '\n'
395 self.output += r"\begin{longtable}{" + str(columnspecs) + r"}" + '\n'
396 self.output += r"\caption{" + str(caption) + r"}\\" + '\n'
397 self.output += r"\toprule" + '\n'
398 self.output += head + r"\\" + '\n'
399 self.output += r"\midrule" + '\n'
400
401 self.format_string = format_string
402

Member Function Documentation

◆ __str__()

__str__ ( self)
inherited
Transform object to string, in this case, just returns .the generated latex-code

Definition at line 26 of file b2latex.py.

26 def __str__(self):
27 """
28 Transform object to string, in this case, just returns .the generated latex-code
29 """
30 return self.output
31

◆ add()

add ( self,
* args,
** kwargs )
Add a new row to the longtable by generating the row using the format_string given in init and the provided dictionary. @param args positional arguments used to generate the row using the python-style format string. @param kwargs dictionary used to generate the row using the python-style format-string.

Reimplemented from LatexObject.

Definition at line 403 of file b2latex.py.

403 def add(self, *args, **kwargs):
404 """
405 Add a new row to the longtable by generating the row using the format_string given in init
406 and the provided dictionary.
407 @param args positional arguments used to generate the row using the python-style format string.
408 @param kwargs dictionary used to generate the row using the python-style format-string.
409 """
410 self.output += self.format_string.format(*args, **kwargs) + r"\\" + '\n'
411 return self
412

◆ finish()

finish ( self,
tail = '' )
Adds optional tail of the table, ends longtable and centered environment. @param tail optional tail, like head but at the bottom of the table.

Reimplemented from LatexObject.

Definition at line 413 of file b2latex.py.

413 def finish(self, tail=''):
414 """
415 Adds optional tail of the table, ends longtable and centered environment.
416 @param tail optional tail, like head but at the bottom of the table.
417 """
418 self.output += r"\bottomrule" + '\n'
419 if str(tail) != '':
420 self.output += str(tail) + r"\\" + '\n'
421 self.output += r"\bottomrule" + '\n'
422 self.output += r"\end{longtable}" + '\n'
423 self.output += r"\end{center}" + '\n'
424 return self
425
426

◆ save()

save ( self,
filename,
compile = False )
inherited
Saves the latex-code into a file, adds preamble and end of document, and compiles the code if requested. @param filename latex-code is stored in this file, should end on .tex @param compile compile the .tex file using pdflatex into a .pdf file

Definition at line 47 of file b2latex.py.

47 def save(self, filename, compile=False):
48 """
49 Saves the latex-code into a file, adds preamble and end of document,
50 and compiles the code if requested.
51 @param filename latex-code is stored in this file, should end on .tex
52 @param compile compile the .tex file using pdflatex into a .pdf file
53 """
54 output = r"""
55 \documentclass[10pt,a4paper]{article}
56 \usepackage[latin1]{inputenc}
57 \usepackage[T1]{fontenc}
58 \usepackage{amsmath}
59 \usepackage{amsfonts}
60 \usepackage{amssymb}
61 \usepackage{graphicx}
62 \usepackage{caption}
63 \usepackage{lmodern}
64 \usepackage{placeins}
65 \usepackage{multicol}
66 \usepackage{tikz}
67 \usetikzlibrary{shapes.arrows,chains, positioning}
68 \usepackage{booktabs} %professional tables
69 \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
70 \usepackage{microtype} %optimises spacing, needs to go after fonts
71 \usepackage{hyperref} %adds links (also in TOC), should be loaded at the very end
72 \usepackage{longtable}
73 \usepackage{color}
74 \usepackage{listings}
75
76 \definecolor{gray}{rgb}{0.4,0.4,0.4}
77 \definecolor{darkblue}{rgb}{0.0,0.0,0.6}
78 \definecolor{cyan}{rgb}{0.0,0.6,0.6}
79
80 \lstset{
81 basicstyle=\ttfamily\scriptsize,
82 columns=fullflexible,
83 showstringspaces=false,
84 commentstyle=\color{gray}\upshape
85 }
86
87 \lstdefinelanguage{XML}
88 {
89 morestring=[b]",
90 morestring=[s]{>}{<},
91 morecomment=[s]{<?}{?>},
92 stringstyle=\color{black},
93 identifierstyle=\color{darkblue},
94 keywordstyle=\color{cyan},
95 morekeywords={xmlns,version,type}% list your attributes here
96 }
97
98 \usepackage[load-configurations=abbreviations]{siunitx}
99 \makeatletter
100 % In newer versions of latex there is a problem with the calc package and tikz
101 % http://tex.stackexchange.com/questions/289551/how-to-resolve-conflict-between-versions-of-texlive-and-pgf
102 \def\pgfmathparse@#1{%
103 % Stuff for calc compatibility.
104 \let\real=\pgfmath@calc@real
105 \let\minof=\pgfmath@calc@minof
106 \let\maxof=\pgfmath@calc@maxof
107 \let\ratio=\pgfmath@calc@ratio
108 \let\widthof=\pgfmath@calc@widthof
109 \let\heightof=\pgfmath@calc@heightof
110 \let\depthof=\pgfmath@calc@depthof
111 % No (math) units yet.
112 \global\pgfmathunitsdeclaredfalse
113 \global\pgfmathmathunitsdeclaredfalse
114 % Expand expression so any remaining CSs are registers
115 % or box dimensions (i.e. |\wd|, |\ht|, |\dp|).
116 \edef\pgfmath@expression{#1}%
117 %
118 \expandafter\pgfmathparse@trynumber@loop\pgfmath@expression\pgfmath@parse@stop
119 %
120 % this here is the _real_ parser. it is invoked by
121 % \pgfmathparse@trynumber@loop if that says "this is no number"
122 %\pgfmathparse@@\pgfmath@parse@stop%
123 }
124 \makeatother
125 \begin{document}
126 """
127 output += self.output
128 output += r"\end{document}"
129
130 with open(filename, 'w') as f:
131 f.write(output)
132 if compile:
133 for i in range(0, 2):
134 ret = subprocess.call(['pdflatex', '-halt-on-error', '-interaction=nonstopmode', filename])
135 if ret != 0:
136 raise RuntimeError("pdflatex failed to create FEI summary PDF, please check.")
137 return self
138
139

Member Data Documentation

◆ format_string

format_string = format_string

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

Definition at line 401 of file b2latex.py.

◆ output

str output = ''
inherited

Stores the outputted latex-code.

Definition at line 24 of file b2latex.py.


The documentation for this class was generated from the following file: