SLiCAPformatter.py — SLiCAP 3.5.1 documentation

# SLiCAPformatter.py

Classes and functions used by the formatters.

class Snippet(snippet: str = '', format: None | str = None)

  Text snippet created by the formatters.

  property format

    Will be set by the formatter method.

  save(filenameOrPath: str | Path)

    Saves the snippet.

    If the path is absolute, it saves it in that location. Otherwise, the preffix and suffix are added according to format:

    > - latex

    >   - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> tex_snippets

    >   - suffix: ‘.tex’

    > - rst

    >   - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> rst_snippets

    >   - suffix: ‘.rst’

    > - myst

    >   - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> myst_snippets

    >   - suffix: ‘.md’

    > - html

    >   - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> html_snippets

    >   - suffix: ‘.html

    > - md

    >   - prefix: project folder -> SLiCAP.ini -> [projectpaths] -> md_snippets

    >   - suffix: ‘.md’

  property snippet

    Will be set by the formatter method.

class formatter(format)

  Formatter with of which the type can be set with the parameter format and snippets can be created with formatter methods.

  Parameters:

    format (str) –

    formatter type; can be one of the following:

    - latex: provides LaTeX formatting

    - rst: provides ReStructuredText formatting

    - myst: not (yet) implemented

    - md: not (yet) implemented

    - html: not (yet) implemented

  Example:

      >>> import SLiCAP as sl
      >>> ltx = sl.formatter("latex") # Creates a LaTeX formatter
      >>> rst = sl.formatter("rst")   # Creates a ReStructuredText formatter

  coeffsTransfer(transferCoeffs, label='', append2caption='', position=0)

    Creates tables with coefficients of the numerator and the denominator of a rational expression.

    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.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

    Example:

        >>> import SLiCAP as sl
        >>> import sympy as sp
        >>>
        >>> ltx  = sl.formatter("latex")
        >>> 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").save("coeffs")

  dcvarContribs(resultObject, label='', append2caption='', position=0)

    Creates a table with results of dcvar analysis stored in resultObject.

    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.

      - append2caption (str) – Text that will be appended to the default table caption(s).

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  elementData(circuitObject, label='', append2caption='', position=0)

    Creates a table with data of expanded netlist elements of circuitObject.

    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.

      - append2caption (str) – Text that will be appended to the default table caption.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  eqn(LHS, RHS, units='', label='', multiline=False, position=0)

    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 (Bool) – True breaks the equation over multiple lines

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

    Example:

        >>> import SLiCAP as sl
        >>> import sympy as sp
        >>>
        >>> ltx = sl.formatter("latex")
        >>> lhs = sp.sympify("e^(1j*pi)")
        >>> rhs = sp.N(-1)
        >>> ltx.eqn(lhs, rhs, label="nice_eqn").save("nice_eqn")

  eqnInline(LHS, RHS, units='', name=None)

    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

      - name (str:) – Name of the variable for RST substitution.

  expr(expr, units='', name=None)

    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

      - name (str:) – Name of the variable for RST substitution.

  file(fileName, lineRange=None, firstNumber=None, firstLine=None, language=None, style=None, position=0)

    Creates a LaTeX input{} or an RST ‘.. literalinclude:: ‘ 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) –

        (LaTeX only) SLiCAP built-in languages:

        - ltspice

      - position (int) – Number of spaces to indent (RST only)

      - style (str) –

        (LaTeX only) SLiCAP built-in styles:

        - slicap

        - latex

      - position – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  matrixEqn(Iv, M, Dv, label='', position=0)

    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.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  monomialCoeffs(monomialCoeffs, label='', caption='', position=0)

    Creates and returns a table table with monomials and their coefficients.

    Parameters:

      - monomialCoeffs –

        Dictionary with key-value pairs:

        - key: monomial (sympy.Expr, sympy.Symbol)

        - value: coefficient of this monomial (sympy.Expr, sympy.Symbol)

      - label (str) – Reference label for the table. Defaults to an empty string.

      - caption (str) – Table caption.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  netlist(netlistFile, lineRange=None, firstNumber=None, position=0)

    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

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

    Example:

      latex

        >>> import SLiCAP as sl
        >>> ltx = sl.formatter("latex") # 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() # See below.

    Example:

      ReStructuredText

        >>> import SLiCAP as sl
        >>> rst = sl.formatter("rst") # Creates a ReStructuredText formatter
        >>> rst.netlist("myFirstRCnetwork.cir").save("netlist")

    This will save a file netlist.rst in the sl.ini.rst_snippets folder with the following contents:

        .. literalinclude:: <full path to myFirstRCnetwork.cir>
            :linenos:

  noiseContribs(resultObject, label='', append2caption='', position=0)

    Creates a table with results of noise analysis stored in resultObject.

    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.

      - append2caption (str) – Text that will be appended to the default table caption(s).

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  parDefs(circuitObject, label='', append2caption='', position=0)

    Creates a table with parameter definitions of circuitObject.

    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.

      - append2caption (str) – Text that will be appended to the default table caption.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  params(circuitObject, label='', append2caption='', position=0)

    Creates a table with undefined parameters of circuitObject.

    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.

      - append2caption (str) – Text that will be appended to the default table caption.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  pz(resultObject, label='', append2caption='')

    Creates a table or tables with results of pole/zero analysis stored in resultObject.

    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.

      - append2caption (str) – Text that will be appended to the default table caption(s).

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  specs(specs, specType, label='', caption='', position=0)

    Creates a table with specifications of type specType.

    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.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet

  stepArray(stepVars, stepArray, label='', caption='', position=0)

    Creates a table with step array values.

    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.

      - position (int) – Number of spaces to indent (RST only)

    Returns:

      SLiCAP Snippet object

    Return type:

      SLiCAP.SLiCAPformatter.Snippet