TeXBase¶
- Author
Marcel Simader
- Date
11.07.2021
New in version v0.1.0.
TeXError¶
- final class TeXError(msg, obj)¶
Exception class for the
SEPTeX
package. This error keeps track of the TeX object which caused the error (seeobj
attribute).
TeXHandler¶
- final class TeXHandler(indent_level=0, *, line_wrap_length=None)¶
TeXHandler
aids as container for lines of text to be written to a document. This class can automatically apply a specific level of indentation and hard-wrap lines that are too long.Note
The algorithm for the hard-wrap will only be applied when the
wrap_lines()
method is called manually. The results of these calls will be stored in the instance. Furthermore, the algorithm will split up lines that are too long at available spaces. If no space is found, the line simply must exceed the given bounds.- Parameters
indent_level (int) – the number of tab character to place at the beginning of each line
line_wrap_length (Optional[int]) – keyword-only argument, when set to an int this value dictates how long a line can be before a pseudo soft-wrap is applied during the
write()
operations of this instance
- property data: Tuple[Tuple[int, str]]¶
- Returns
a tuple of strings where each string is exactly one line in the document
- property indent_level: int¶
- Returns
what the default amount of indentation for this handler should be
- property line_wrap_length: Optional[int]¶
- Returns
the number of characters before a line is split into two using a soft-wrap, this means that in the handler, the line will still only have one entry but contain the newline character
- wrap_lines(*, tab_width=4, hanging_indent=True)¶
Wraps the lines of this instance according to
line_wrap_length
.- Parameters
tab_width (int) – how wide (in characters) to consider a tab character (
\t
)hanging_indent (bool) – whether or not to indent wrapped lines by one extra tab
- write(s)¶
Write object
s
to the handler.If
s
is a string or bytes object, this function will perform some processing. Ifs
is aTeXHandler
this function will extend the data of this instance with the given handler, and add the required number of tabs of this instance to the tabs already accumulated in the data tuple of the given handler.- Parameters
s (Union[AnyStr, SEPTeX.TeXBase.TeXHandler]) – the object to write, can be a
TeXHandler
or any string of any length including line breaks
- newline()¶
Write an empty line.
TeXResource¶
- class TeXResource(*, can_reopen=False)¶
Abstract base class for marking a class as having an open and closed state, along with TeX text data of some sort. This class requires
to_tex()
to be implemented to provide the contents of the handlers to any other caller.In addition to the open and closed states, one can configure the resource to allow multiple openings. The default behaviour is to throw an exception if the resource is opened a second time. The opening and closing is implemented as context manager, with
__enter__()
triggering an opening and__exit__()
triggering a closing. The private helper methods__require_closed__()
,__require_open__()
,__require_virgin__()
, and__require_used__()
are provided to check these states.- Parameters
can_reopen – keyword-only argument, determines whether or not opening this instance multiple times raises a
TeXError
, defaults toFalse
- property open: bool¶
- Returns
whether or not this resource is currently opened
- final __require_closed__(frame_depth=1)¶
Requires a resource to be closed.
- Parameters
frame_depth (int) – how many stack frames to go backwards in order to retrieve the name of the function which represents the public API call which caused the error
- Raises
LaTeXError – if the resource is open when this function is called
- final __require_open__(frame_depth=1)¶
Requires a resource to be opened.
- Parameters
frame_depth (int) – how many stack frames to go backwards in order to retrieve the name of the function which represents the public API call which caused the error
- Raises
LaTeXError – if the resource is closed when this function is called
- final __require_virgin__(frame_depth=1)¶
Requires a resource to have never been opened.
- Parameters
frame_depth (int) – how many stack frames to go backwards in order to retrieve the name of the function which represents the public API call which caused the error
- Raises
LaTeXError – if the resource has been opened once before when this function is called
- final __require_used__(frame_depth=1)¶
Requires a resource to have been opened and closed at least once in the past.
- Parameters
frame_depth (int) – how many stack frames to go backwards in order to retrieve the name of the function which represents the public API call which caused the error
- Raises
LaTeXError – if the resource has not been opened and closed at least once in the past when this function is called
- abstract to_tex()¶
Converts this object to a TeX string.