Beispiel #1
0
 def __init__(self, content, language: str):
     self.init_data()
     self.data.packages.append(Package('minted'))
     self.data.flags.append(HAS_MINTED)
     super().__init__(self.name,
                      content,
                      env_modifiers=self._wrap_with_braces(language))
 def _include_references_file(self,
                              references: Optional[
                                  Sequence[BibTexEntryBase]] = None):
     from pyexlatex.logic.builder import _build
     all_references = _build(references)
     references_inline_file = FileContents(all_references, 'refs.bib')
     self.data.end_document_items.append(references_inline_file)
     self.data.packages.append(Package('filecontents'))
 def __init__(self,
              references: Optional[Sequence[BibTexEntryBase]] = None,
              style_name: str = 'plain'):
     self.references = references
     style_manager = StyleManager()
     self.style = style_manager.get_style_by_name(style_name)
     self.add_data_from_content(self.style)
     self._include_references_file(references)
     self.data.packages.append(Package('natbib', eq_on_modifier=False))
Beispiel #4
0
    def construct_packages(self, packages: List[Package]=None,
                           page_modifier_str: Optional[str]='margin=0.8in, bottom=1.2in',
                           appendix_modifier_str: Optional[str] = 'page',
                           floats_at_end: bool = False, floats_at_end_options: str = 'nolists',
                           line_spacing: Optional[float] = None,
                           tables_relative_font_size: int = 0, figures_relative_font_size: int = 0) -> List[Package]:
        from pyexlatex.texgen.packages.default import default_packages

        all_packages: List[ItemBase]
        if packages is None:
            all_packages = default_packages.copy()
        else:
            all_packages = deepcopy(packages)

        if page_modifier_str is not None:
            # Set margins, body size, etc. with geometry package
            all_packages.append(Package('geometry', modifier_str=page_modifier_str))

        all_packages.extend(
            get_table_figure_size_packages(tables_relative_font_size, figures_relative_font_size)
        )

        if floats_at_end:
            all_packages.extend([
                Package('endfloat', modifier_str=floats_at_end_options if floats_at_end_options else None),
                DeclareDelayedFloatFlavor('ltable', 'table'),  # treat custom environment ltable (landscape table) as table
                DeclareDelayedFloatFlavor('lfigure', 'figure') # treat custom environment lfigure (landscape figure) as figure
            ])

        if line_spacing:
            all_packages.extend([
                Package('setspace'),
                LineSpacing(line_spacing)
            ])

        all_packages.append(Package('appendix', modifier_str=appendix_modifier_str))

        return all_packages
Beispiel #5
0
    def __init__(
            self,
            content: ItemOrListOfItems,
            packages: List[Package] = None,
            pre_env_contents: Optional[ItemOrListOfItems] = None,
            name: Optional[str] = None,
            contact_lines: Optional[Sequence[Union[str,
                                                   Sequence[str]]]] = None,
            font_size: Optional[float] = 11,
            page_modifier_str: Optional[
                str] = 'left=0.75in,top=0.6in,right=0.75in,bottom=0.6in',
            authors: Optional[Union[str, Sequence[str]]] = None,
            pre_output_func: Optional[Callable] = None):

        self.init_data()

        self.document_class_obj = DocumentClass(
            document_type='resume',
            font_size=font_size,
        )

        from pyexlatex.models.item import ItemBase
        if pre_env_contents is None:
            pre_env_contents_list = []
        elif isinstance(pre_env_contents, (ItemBase, str)):
            pre_env_contents_list = [pre_env_contents]
        else:
            pre_env_contents_list = pre_env_contents  # type: ignore

        name = self._get_name(name, authors)

        if name is not None:
            pre_env_contents_list.append(Name(name))

        if contact_lines is not None:
            pre_env_contents_list.extend(
                [ContactLine(contact_info) for contact_info in contact_lines])

        if page_modifier_str is not None:
            # Set margins, body size, etc. with geometry package
            self.data.packages.append(
                Package('geometry', modifier_str=page_modifier_str))

        super().__init__(
            content,
            packages=packages,
            pre_env_contents=pre_env_contents_list,
            pre_output_func=pre_output_func,
        )
Beispiel #6
0
def _filepaths_to_document_or_figure(filepaths,
                                     subfigure_kwargs={},
                                     figure_kwargs={},
                                     document_kwargs={},
                                     as_document=True):
    subfigures = [Subfigure(fp, **subfigure_kwargs) for fp in filepaths]
    figure = Figure(subfigures, **figure_kwargs)

    if not as_document:
        return figure

    simple_package_strs = ['caption', 'subcaption', 'graphicx', 'pdflscape']
    simple_packages = [Package(str_) for str_ in simple_package_strs]

    packages = simple_packages + [
    ]  # add any packages with options here with the Package class

    document = Document(figure, packages, **document_kwargs)

    return document
Beispiel #7
0
    def __init__(self, href: str, content: Optional[Any] = None, **kwargs):
        self.href = href
        self.content = content

        options: Sequence[Any]
        if content is None:
            self.name = 'url'
            options = (href,)
        else:
            self.name = 'href'
            options = (href, content)

        self.add_data_from_content(content)
        self.data.packages.append(
            # TODO [#14]: Figure out way to have different options for different hyperlinks
            #
            # Think about passing options. Difficult because mutliple Hyperlinks could be constructed with
            # different options, then not clear which to take.
            Package('hyperref', modifier_str='hidelinks', eq_on_modifier=False)
        )

        MultiOptionSimpleItem.__init__(self, self.name, *options, **kwargs)
Beispiel #8
0
def get_table_figure_size_packages(
    tables_relative_font_size: int = 0,
    figures_relative_font_size: int = 0,
    floatrow_table_options: str = 'capposition=top',
    floatrow_figure_options: str = 'capposition=top',
) -> List[ItemBase]:
    all_packages = []
    if tables_relative_font_size or figures_relative_font_size:
        all_packages.append(Package('floatrow'))
        if tables_relative_font_size:
            declared_font = DeclareFloatFont(tables_relative_font_size)
            float_setup_str = f'font={declared_font.size_def.name},{floatrow_table_options}'
            all_packages.extend([
                declared_font,
                FloatSetup('table', float_setup_str),
            ])
        if figures_relative_font_size:
            declared_font = DeclareFloatFont(figures_relative_font_size)
            float_setup_str = f'font={declared_font.size_def.name},{floatrow_figure_options}'
            all_packages.extend([
                declared_font,
                FloatSetup('figure', float_setup_str),
            ])
    return all_packages
Beispiel #9
0
    def _as_package(self, package: Union[Package, str]):
        if isinstance(package, str):
            return Package(package)

        return package
Beispiel #10
0
 def __init__(self, item_accessor):
     self.init_data()
     self.data.packages.append(Package('natbib', eq_on_modifier=False))
     super().__init__(item_accessor)
Beispiel #11
0
 def __init__(self,
              contents,
              env_modifiers: Optional[Sequence[str]] = None):
     self.init_data()
     self.data.packages.append(Package('tikz'))
     super().__init__(self.name, contents, env_modifiers=env_modifiers)
Beispiel #12
0
from typing import Union, List

from pyexlatex.models.package import Package

simple_package_strs = [
    'caption', 'subcaption', 'graphicx', 'pdflscape', 'fancyhdr', 'lastpage',
    'textcomp'
]
simple_packages = [Package(str_) for str_ in simple_package_strs]

direct_packages: List[Package] = []

default_packages = simple_packages + direct_packages  # add any packages with options here with the Package class
Beispiel #13
0
 def __init__(self, contents, adjust_options: Sequence[str]):
     self.adjust_options = adjust_options
     self.init_data()
     self.data.packages.append(Package('adjustbox'))
     super().__init__(self.name, contents, env_modifiers=self.options_str)
Beispiel #14
0
from pyexlatex.models.package import Package
from pyexlatex.texgen.packages.columntypes import ColumnTypesPackage

_default_package_strs = [
    'amsmath', 'pdflscape', 'booktabs', 'array', 'threeparttable', 'fancyhdr',
    'lastpage', 'textcomp'
]

_direct_default_packages = [
    ColumnTypesPackage(),
    Package('fontenc', modifier_str='T1'),  # allows printing of > and <
]

default_packages = [
    Package(package_str) for package_str in _default_package_strs
] + _direct_default_packages  # type: ignore