auto
  
   	�236ÇÆÅ  ì    	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ä583_‘I|¥‰ÓMdœv ©ƒ†ü+=ÉÈ G    ‹      ÍUÑnÓ0}ßW?ð–Ü&ÍtiÐh&Q­k«®!Äƒ;‰µÄŽlweûzœ¦Ýj)4xÊµsîõ9ç^Ùá‹x6Z~š_¢÷Ëë	šx7�v >öG ñ2nnÏ¸œb„cêÀz½v×}Wª–(LU �â©q©¡8:	›½è…#Ô~Qh¸)Y4”}E2C WFsÊlåz•”<Ým ••ÍÍxÉ\Ê*éÚM¥¬íAT¦ÚÑº|L÷á�T¡@êÚf©;ž2½À°ª.‰aÀ…aª–6æR 9,„–“e	[ša"é}ÃÞûÏ˜ZBI²!Ü„*
M�îHÉs1ÄFÖ8
y•#­Ò!žJ¡!)‰¸usžaDJ3ÄŸÇ£Ù‹S4ÙQHP¡X6ÄoGÃéùlãhJ*{Ù�¹¶˜Mˆ6¨’”gœÑƒà›|ÃŒ[LÌtªxÝH~‚‚•Ø•šÊR×Äj=µ

ÕEµzÌ’~gÆübq9]ÆãEk	mJ<±û§}ÇÑœ(&Š¹b©‘ê~ëKKò¥Ht}¾[¢­jÅóÂà!íEþ†U+q+äZtÝ²�ØëSM”ãªG�a—ììüžæxžãõ‘ßxo:tÏ®žQ†QÍt4*vÑ1½Àñ_!¯7‚ƒ"‚Þé÷"“%µ®v4ÙsØ*€¿Áÿ™g©)D‰÷M#º«£bìP½n&Êïn†ÛûÉDýâMÛ;8„Í[BûÒ}ô�L    A   ˆl–Ãa¾”Êi?u	Aà¸&TÅ£�þBãY²ÈFÀû%Œ„óÇƒhM‡Æ_ŠI|¥�+Wé3ž¯ËÊ ›    #!/usr/bin/env python3

# Copyright 2020-2022 Louis Paternault
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

"""Compile a `.tex` file, executing commands that are set inside the file itself."""

import argparse
import logging
import os
import pathlib
import re
import subprocess
import sys

NAME = "SpiX"
VERSION = "1.3.0"

RE_EMPTY = re.compile("^ *$")
RE_COMMENT = re.compile("^ *%")
RE_COMMAND = re.compile(r"^%\$ ?(.*)$")


class SpixError(Exception):
    """Exception that should be catched and nicely displayed to user."""


def parse_lines(lines):
    """Parse line to find code snippets.

    :param iterable lines: Lines to parte (typically ``open("foo.tex").readlines()``.
    :return: Iterator over snippets (as strings).
    """
    snippet = None
    for line in lines:
        line = line.rstrip("\n")
        if RE_COMMAND.match(line):
            match = RE_COMMAND.match(line)
            if snippet is None:
                snippet = ""
            else:
                snippet += "\n"
            snippet += match.groups()[0]
        elif RE_EMPTY.match(line) or RE_COMMENT.match(line):
            if snippet is not None:
                yield snippet
                snippet = None
        else:
            break
    if snippet is not None:
        yield snippet


def compiletex(filename, *, dryrun=False):
    """Read commands from file, and execute them.

    :param str filename: File to process.
    :param bool dryrun: If ``True``, print commands to run, but do not execute them.
    """
    env = os.environ
    filename = pathlib.Path(filename)
    env["texname"] = filename.name
    env["basename"] = filename.stem

    try:
        # pylint: disable=unspecified-encoding
        with open(filename, errors="ignore") as file:
            for snippet in parse_lines(file.readlines()):
                print(snippet)
                sys.stdout.flush()
                if dryrun:
                    continue

                subprocess.check_call(
                    ["sh", "-c", snippet, NAME, filename.name],
                    cwd=(pathlib.Path.cwd() / filename).parent,
                    env=env,
                )
    except subprocess.CalledProcessError as error:
        raise SpixError() from error
    except IsADirectoryError as error:
        raise SpixError(str(error)) from error


def commandline_parser():
    """Return a command line parser.

    :rtype: argparse.ArgumentParser
    """
    parser = argparse.ArgumentParser(
        prog="spix",
        