SLiCAPlatex.py
SLiCAP formatterfor generating snippets that can be stored as LaTeX files and included in other LaTeX files.
- class LaTeXformatter
Latex formatter. The methods return LaTeX snippets.
- Example:
>>> import SLiCAP as sl >>> sl.initProject("formatter") >>> ltx = sl.LaTeXformatter() # Creates an instance of a LaTeX formatter
- coeffsTransfer(transferCoeffs, label='', caption='', color='myyellow')
Creates a tablestable that displays the numerator and denominator coefficients of a rational expression. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
stepVars (list) – List with step variables (str, sympy.Symbol).
stepArray (List) – List with lists with step values for each step variable
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Table caption.
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- Example:
>>> import SLiCAP as sl >>> import sympy as sp >>> >>> ltx = sl.LaTeXformatter() >>> expr = sp.sympify("A_0*(1+s*b_1)/(((1+s*a_1))*((1+s*a_2)))") >>> tr_coeffs = sl.coeffsTransfer(expr) >>> ltx.coeffsTransfer(tr_coeffs, label="tab-coeffs", caption = "numerator and denominator " + "coefficients").save("coeffs")
- dcvarContribs(resultObject, label='', caption='', color='myyellow')
Creates a table with results of dcvar analysis stored in resultObject. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
resultObject (SLiCAP.SLiCAPprotos.allResults) – SLiCAP circuit object that comprises the circuit data to be listed.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Text that will used as table caption(s).
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- dictTable(dct, head=None, label='', caption='', color='myyellow')
Creates a table from a dictionary; optionally with a header. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
dct – Dictionary with key-value pairs.
head (list) – List with names for the key column and the value column, respectively. List items will be converted to string.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Text that will used as table caption.
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- Example:
>>> import SLiCAP as sl >>> >>> sl.initProject("Documentation") >>> ltx = sl.LaTeXformatter() >>> header = ["name", "age"] >>> data = {"John": 89, Mary: 104} >>> ltx.dictTable(data, head=header, caption="Some of my friends").save("friends")
- elementData(circuitObject, label='', caption='', color='myyellow')
Creates a table with data of expanded netlist elements of circuitObject. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
circuitObject (SLiCAP.SLiCAPprotos.circuit) – SLiCAP circuit object that comprises the circuit data to be listed.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Text that will used as table caption.
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- eqn(LHS, RHS, units='', label='', multiline=False)
Creates a displayed (numbered) equation.
- Parameters:
LHS (str, sympy.Symbol, sympy.Expr) – Left hand side of the equation.
RHS (sympy.Symbol, sympy.Expr) – Right hand side of the equation.
units (str) – Units
label (str) – Reference label for the table. Defaults to an empty string.
multiline (int, Bool) – n breaks the equation over multiple lines with n sums or products per line
- Returns:
SLiCAP Snippet object
- Return type:
- Example:
>>> import SLiCAP as sl >>> import sympy as sp >>> >>> ltx = sl.LaTeXformatter() >>> lhs = sp.sympify("e^(1j*pi)") >>> rhs = sp.N(-1) >>> ltx.eqn(lhs, rhs, label="nice_eqn").save("nice_eqn")
- eqnInline(LHS, RHS, units='')
Creates in inline equation. If format=’rst’, this equation is stored (name = equation) in the file ‘substitutions.rst’. The location of this file is given in the file:
SLiCAP.ini -> [projectpaths] -> rst_snippets
- Parameters:
LHS (sympy.Expr, str) – Left hand side of the equation
RHS (sympy.Expr) – Right hand side of the equation
units (str) – Units
- expr(expr, units='')
Creates in inline expression. If format=’rst’, this expression is stored (name = expr) in the file ‘substitutions.rst’. The location of this file is given in the file:
SLiCAP.ini -> [projectpaths] -> rst_snippets
- Parameters:
expr – Expression
units (str) – Units
- file(fileName, lineRange=None, firstNumber=None, language=None, style=None)
Creates a LaTeX input{} command for literally displaying a file.
- Parameters:
fileName (str) – Name of the file. Path is absolute or relative to the project directory
lineRange (str) – range of lines to be included
firstNumber (str) – start number of the displayed line numbers
language (str) –
SLiCAP built-in languages:
ltspice
style (str) –
SLiCAP built-in styles:
slicap
latex
- Returns:
SLiCAP Snippet object
- Return type:
- matrixEqn(Iv, M, Dv, label='')
Creates a displayed matrix equation without evaluating it.
- Parameters:
Iv (sympy.Matrix) – Left hand side of the equation: vector with independent variables
M (sympy.Matrix) – Right hand side of the equation: matrix
Dv (sympy.Matrix) – Righthand side of the equation: vector with dependent variables
label (str) – Reference label for the table. Defaults to an empty string.
- Returns:
SLiCAP Snippet object
- Return type:
- nestedLists(headerList, linesList, unitpos=None, caption='', label='', color='myyellow')
Creates and returns a LaTeX table snippet that can be included in a LaTeX document. Each list is converted into a table row and must have equal lengths. There can be one column with units.
A label can be given as reference and a caption can be added.
- Parameters:
headerList (list with strings) – List with column headers.
linesList (list) – List with lists of table data for each table row
unitpos (int, str) – Position of column with units (will be typesetted with mathrm)
caption (str) – Table caption, defauls to ‘’
label (str) – Table reference label
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
LaTeX snippet to be included in a LaTeX document
- Return type:
str
- netlist(netlistFile, lineRange=None, firstNumber=None)
Creates a LaTeX input{} or an RST ‘.. literalinclude:: ‘ command for including a netlist file.
- Parameters:
netlistFile (str) – Name of the netlist file relative to the project circuit directory
lineRange (str) – range of lines to be included
firstNumber (str) – start number of the displayed line numbers
- Returns:
SLiCAP Snippet object
- Return type:
- Example:
latex
>>> import SLiCAP as sl >>> ltx = sl.LaTeXformatter() # Creates a LaTeX formatter >>> latex_netlist = ltx.netlist("myFirstRCnetwork.cir") >>> latex_netlist.save("netlist")
This will save a file netlist.tex in the sl.ini.tex_snippets folder with the following contents:
\textbf{Netlist: myFirstRCnetwork.cir} \lstinputlisting[language=ltspice, numbers=left]{<full path to myFirstRCnetwork.cir>}
The netlist file is assumed to reside in the folder given by sl.ini.cir_path. If you want to include a file from any other location, use:
>>> ltx.file()
- noiseContribs(resultObject, label='', caption='', color='myyellow')
Creates a table with results of noise analysis stored in resultObject. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
resultObject (SLiCAP.SLiCAPprotos.allResults) – SLiCAP circuit object that comprises the circuit data to be listed.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Text that will used as table caption(s).
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- parDefs(circuitObject, label='', caption='', color='myyellow')
Creates a table with parameter definitions of circuitObject. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
circuitObject (SLiCAP.SLiCAPprotos.circuit) – SLiCAP circuit object that comprises the circuit data to be listed.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Text that will used as table caption.
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- params(circuitObject, label='', caption='', color='myyellow')
Creates a table with undefined parameters of circuitObject. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
circuitObject (SLiCAP.SLiCAPprotos.circuit) – SLiCAP circuit object that comprises the circuit data to be listed.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Text that will used as table caption.
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- pz(resultObject, label='', caption='', color='myyellow')
Creates a table or tables with results of pole/zero analysis stored in resultObject. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
resultObject (SLiCAP.SLiCAPprotos.allResults) – SLiCAP circuit object that comprises the circuit data to be listed.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Text that will used as table caption(s).
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- specs(specs, specType, label='', caption='', color='myyellow')
Creates a table with specifications of type specType. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
specs (list) – List with SLiCAP.SLiCAPdesignData.specItem objects.
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Table caption.
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- stepArray(stepVars, stepArray, label='', caption='', color='myyellow')
Creates a table with step array values. If no label AND no caption are given this method returns a LaTeX tabular snippet. Else it returns a table snippet.
- Parameters:
stepVars (list) – List with step variables (str, sympy.Symbol).
stepArray (List) – List with lists with step values for each step variable
label (str) – Reference label for the table. Defaults to an empty string.
caption (str) – Table caption.
color (str) – Alternate row color name, should be defined in ‘preambuleSLiCAP.tex’ defaults to ‘myyellow’. Use None for no background color.
- Returns:
SLiCAP Snippet object
- Return type:
- sub2rm(textext)
Converts italic fonts LaTeX subscripts into mathrm fonts.
- Parameters:
textext – LaTeX snippet
- Returns:
Modified LaTeX snippet
- Return type:
str
- Example:
>>> textext = "\frac{V_{out}}{V_{in}}" >>> print(sub2rm(textext)) \frac{V_{\mathrm{out}}}{V_{\mathrm{in}}}