def builddep(styfiles):
    allinfos = {
        PACKAGE_ID: defaultdict(set),
        TIKZLIB_ID: set(),
    }

    for onestyfile in styfiles:
        relative_path = onestyfile - THIS_DIR
        parentname    = onestyfile.parent.name

        print(f"{DECO}* Analyzing << {relative_path} >>")

        with open(
            file     = onestyfile,
            encoding = "utf-8"
        ) as filetoupdate:
            _, packages, definitions = between(
                text = filetoupdate.read(),
                seps = [
                    "% == PACKAGES USED == %",
                    "% == DEFINITIONS == %"
                ],
                keepseps = False
            )

        for info in packages.split("\n"):
            info = info.strip()

            if not info:
                continue

            info = analyze(info)

            if info[KIND_ID] == TIKZLIB_ID:
                for onename in info[NAMES_ID]:
                    allinfos[TIKZLIB_ID].add(onename)

            elif info[KIND_ID] == PACKAGE_ID:
                for onename in info[NAMES_ID]:
                    if onename not in allinfos[PACKAGE_ID]:
                        allinfos[PACKAGE_ID][onename] = set(info[OPTIONS_ID])

    return allinfos
Beispiel #2
0
    EXAMPLE_FILES += [
        (l, subdir_exa) for l in subdir.walk("file::examples/**")
    ]

LATEXFILES.sort()

for latexfile in LATEXFILES:
    with latexfile.open(
        mode     = "r",
        encoding = "utf-8"
    ) as texfile:
        _, content, _ = between(
            text = texfile.read(),
            seps = [
                r"\begin{document}",
                r"\end{document}"
            ]
        )

        CONTENTS.append(content)


for peufpath, subdir_exa in EXAMPLE_FILES:
    peufpath.copy_to(
        dest     = EXA_DIR_DEST / (peufpath - subdir_exa),
        safemode = False
    )


# ------------------------- #
Beispiel #3
0
    for latexfile in subdir.walk("file::*.sty"):
        if (latexfile - THIS_DIR).depth == 1:
            paths_found.append(latexfile)

paths_found.sort()

for latexfile in paths_found:
    relative_path = latexfile - THIS_DIR
    parentname = latexfile.parent.name

    print(f"{DECO}* Extracting macros from << {relative_path} >>")

    with open(file=latexfile, encoding="utf-8") as filetoupdate:
        _, packages, definitions = between(
            text=filetoupdate.read(),
            seps=["% == PACKAGES USED == %", "% == DEFINITIONS == %"],
            keepseps=False)

    definitions = cleansource(definitions)

    if definitions.strip():
        if ALL_MACROS:
            ALL_MACROS.append("\n")

        ALL_MACROS += [
            MYFRAME(path2title(relative_path.stem)), "", definitions
        ]

ALL_MACROS = "\n".join(ALL_MACROS)

# ------------------------------ #
Beispiel #4
0
for interkind, defs in config.items():
    fortexdoc = []
    macrosdefs = []

    for prefix, suffix, delimstart, delimend in defs:
        macrosdefs += ["\n", texmacro(prefix, suffix, delimstart, delimend)]

        fortexdoc += ["\n\n\\separation\n\n", "\n", texdoc(prefix, suffix)]

    fortexdoc = "".join(fortexdoc[1:])
    macrosdefs = "".join(macrosdefs)

    interkind = interkind.replace('-', ' ')

    text_start, _, text_end = between(
        text=template_sty,
        seps=[f"% Macros for {interkind} intervals", "% Macros for"],
        keepseps=True)

    template_sty = text_start + "\n" + macrosdefs \
                 + "\n" + text_end

    text_start, _, text_end = between(
        text=template_tex,
        seps=[
            f"% Docs for {interkind} intervals - START",
            f"% Docs for {interkind} intervals - END",
        ],
        keepseps=True)

    template_tex = text_start + "\n" + fortexdoc \
                 + "\n" + text_end
# -- TEMPLATES TO UPDATE -- #
# ------------------------- #

with open(file=STY_FILE, mode='r', encoding='utf-8') as styfile:
    template_sty = styfile.read()

with open(file=TEX_FILE, mode='r', encoding='utf-8') as docfile:
    template_tex = docfile.read()

# --------------------- #
# -- UPDATING MACROS -- #
# --------------------- #

text_start, _, text_end = between(text=template_sty,
                                  seps=[
                                      "% List of classical sets - START",
                                      "% List of classical sets - END"
                                  ],
                                  keepseps=True)

alldefs = []

for setdef in classicalsets:
    alldefs.append(latex_classical(setdef))

alldefs = "\n\n".join(alldefs)
alldefs = f"\n\n{alldefs}\n\n"

template_sty = text_start + alldefs + text_end

# ----------------------- #
# -- TABLE OF SUFFIXES -- #
Beispiel #6
0
with JSON_DEP_PATH.open(mode="w", encoding="utf-8") as jsonfile:
    jsonfile.write(dumps(packages))

# ------------- #
# -- FOR DOC -- #
# ------------- #

packages = [pack for pack in packages['packages']]

if "tnscom" in packages:
    with open(file=DOC_INTRO_TEX, mode='r', encoding='utf-8') as docfile:
        temp_tex = docfile.read()

    text_start, _, text_end = between(
        text=temp_tex,
        seps=["% tnscom used - START", "% tnscom used - END"],
        keepseps=True)

    temp_tex = text_start + """
\\section{Beta-dépendance}

\\verb#tnscom# qui est disponible sur \\url{https://github.com/typensee-latex/tnscom.git} est un package utilisé en coulisse.
""" + text_end

    with open(file=DOC_INTRO_TEX, mode='w', encoding='utf-8') as docfile:
        docfile.write(temp_tex)

    packages = [pack for pack in packages if pack != "tnscom"]

if packages:
    with open(file=DOC_DEP_TEX, mode='r', encoding='utf-8') as docfile:
Beispiel #7
0
with open(
    file     = TEX_FILE,
    mode     = 'r',
    encoding = 'utf-8'
) as docfile:
    template_tex = docfile.read()


# --------------------- #
# -- UPDATING MACROS -- #
# --------------------- #

text_start, _, text_end = between(
    text = template_sty,
    seps = [
        "% Constants - START",
        "% Constants - END"
    ],
    keepseps = True
)

text_start += "\n\n% User's constants\n"
text_end = text_end.lstrip()

text_auto = [
    r"""
\newcommand\param[1]{{%
    \mathop{{{{}}%
        \IfStrEqCase{{#1}}{{%
            {0}
        }}[\text{{\textbf{{#1}}}}]%
    }}%
Beispiel #8
0
for kind, metas in latexcodes.items():
    for i, (exafilename, onetexcode) in enumerate(metas):
        exafilename = exafilename.lower()
        onetexcode = LATEX_N_OUPUT_TEMP.format(latexcode=" " * 2 +
                                               "\n  ".join(onetexcode))

        metas[i] = (exafilename, onetexcode)

    latexcodes[kind] = metas

# ------------------------------ #
# -- USEFUL TEXT MACROS - DOC -- #
# ------------------------------ #

text_start, _, text_end = between(
    text=template_tex,
    seps=["% == Text tools - START == %\n", "\n% == Text tools - END == %"],
    keepseps=True)

texcode = []

for prefix, kind in [
    ("TT", "True Type"),
    ("AL", "algorithme"),
]:
    texcode += [
        f"""
\\begin{{center}}
	Liste des commandes de type \myquote{{{kind}}}.
\\end{{center}}

\\begin{{enumerate}}
with lastppath.open(mode="r", encoding="utf-8") as f:
    for line in f:
        _, lastversion = line.split("verb+", maxsplit=1)
        lastversion, _ = lastversion.split("+", maxsplit=1)
        break

# ------------------------------------ #
# -- UPDATING THE CHANGE LATEX CODE -- #
# ------------------------------------ #

# We have to revrese sort the ppaths found.
allppaths.sort(reverse=True)

with CHANGE_LOG_TEX_FILE.open(mode="r", encoding="utf-8") as f:
    text_start, _, text_end = between(
        text=f.read(),
        seps=["% Changes shown - START", "% Changes shown - END"],
        keepseps=True)

content = ["\n" * 2]

for ppath in allppaths:
    with ppath.open(mode="r", encoding="utf-8") as f:
        firstline = True

        for line in f.readlines():
            if firstline:
                line = f"\\medskip\n{DECO_SPACE}" \
                     + f"\\item[{ppath.parent.stem}-{ppath.stem}] {line}"
                firstline = False

            content.append(DECO_SPACE + line)
    else:
        STY_CONTENT.append(
            template_stars_no_switch.format(macroname=macroname,
                                            latexsymbol=latexsymbol))

STY_CONTENT = "\n\n".join(STY_CONTENT)

# -------------------------- #
# -- UPDATES OF THE FILES -- #
# -------------------------- #

with open(file=STY_FILE, mode='r', encoding='utf-8') as styfile:
    template_sty = styfile.read()

text_start, _, text_end = between(
    text=template_sty,
    seps=[f"% == Decorations - START == %", f"% == Decorations - END == %"],
    keepseps=True)

template_sty = f"""
{text_start}

{STY_CONTENT}

{text_end}
""".strip()

with open(file=STY_FILE, mode='w', encoding='utf-8') as docfile:
    docfile.write(template_sty)
# ------------------------------ #
# -- LATEX TEMPLATE TO UPDATE -- #
# ------------------------------ #

with open(file=STY_FILE, mode='r', encoding='utf-8') as styfile:
    temp_sty = styfile.read()

with open(file=TEX_FILE, mode='r', encoding='utf-8') as docfile:
    temp_tex = docfile.read()

# --------------------- #
# -- UPDATING MACROS -- #
# --------------------- #

text_start, _, text_end = between(
    text=temp_sty,
    seps=["% Classical functions - START", "% Classical functions - END"],
    keepseps=True)

macro_defs = [
    "\n".join(r"\DeclareMathOperator{{\{0}}}{{\operatorname{{{1}}}}}".format(
        latexname, humanname)
              for latexname, humanname in functions['no-parameter'].items()),
    "", "\n".join(
        TEMP_LATEX_PARAM_FUNC.format(name=name)
        for name in functions['parameter'])
]

macro_defs = "\n".join(macro_defs)
macro_defs = macro_defs.strip()

temp_sty = f"{text_start}\n\n{macro_defs}\n\n{text_end}"