# Path: flap/latex/macros/commons.py
# class Macro:
#     """
#     A LaTeX macro, including its name (e.g., 'point'), its signature
#     as a list of expected tokens (e.g., '(#1,#2)') and the text that
#     should replace it.
#     """
# 
#     def __init__(self, flap, name, signature, body):
#         self._flap = flap
#         self._name = name if not name.startswith("\\") else name[1:]
#         self._signature = signature or []
#         self._body = body or iter([])
#         self._called = False
#         self._requires_expansion = False
#         self.is_user_defined = False
# 
#     @property
#     def requires_expansion(self):
#         return self._requires_expansion
# 
#     @property
#     def was_called(self):
#         return self._called
# 
#     @property
#     def name(self):
#         return self._name
# 
#     def execute2(self, parser, invocation):
#         self._called = True
#         pass
# 
#     def rewrite2(self, parser, invocation):
#         return invocation.as_tokens
# 
#     def capture_invocation(self, parser, command):
#         invocation = Invocation(command)
#         self._capture_arguments(parser, invocation)
#         return invocation
# 
#     def _capture_arguments(self, parser, invocation):
#         for index, any_token in enumerate(self._signature):
#             if any_token.is_a_parameter:
#                 parameter = str(any_token)
#                 if index == len(self._signature) - 1:
#                     expression = parser.read.one()
#                     invocation.append_argument(parameter, expression)
#                     logger.debug("Arg '{}' is '{}'".format(
#                         any_token.as_text,
#                         "".join(t.as_text for t in expression)))
#                 else:
#                     next_token = self._signature[index + 1]
#                     value = parser.read.until_text(next_token.as_text)
#                     invocation.append_argument(parameter, value)
#                     logger.debug("Arg '{}' is '{}'".format(
#                         any_token.as_text,
#                         "".join(t.as_text for t in value)))
#             else:
#                 invocation.append(parser.read.text(str(any_token)))
# 
#     def expand(self, invocation):
#         # TODO: Remove, useless as the we don't substitute tokens into
#         # the body anymore
#         result = []
#         for any_token in self._body:
#             if any_token.is_a_parameter:
#                 result += invocation.argument(str(any_token))
#             else:
#                 result.append(any_token)
#         return result
# 
#     def __eq__(self, other):
#         if not isinstance(other, Macro):
#             return False
#         return self._name == other._name and \
#             self._signature == other._signature and \
#             self._body == other._body
# 
#     def __repr__(self):
#         signature, body = "", ""
#         if signature:
#             signature = "".join(map(str, self._signature))
#         if body:
#             body = "".join(map(str, self._body))
#         return r"\def" + self._name + signature + body
# 
# class UpdateLink(Macro):
# 
#     def __init__(self, flap, name):
#         super().__init__(flap, name, None, None)
# 
#     @staticmethod
#     def _capture_arguments(parser, invocation):
#         invocation.append_argument("options", parser.read.options())
#         logger.debug("Options = '%s'", invocation.argument_as_text("options"))
#         invocation.append_argument("link", parser.read.group())
# 
#     def execute2(self, parser, invocation):
#         pass
# 
#     def rewrite2(self, parser, invocation):
#         try:
#             link_tokens = invocation.argument("link")
#             link = parser.evaluate_as_text(invocation.argument("link"))
#             new_link = self.update_link(parser, link, invocation)
#             opening = str(link_tokens[0])
#             closing = str(link_tokens[-1])
#             return invocation\
#                 .substitute("link",
#                             parser._create.as_list(opening + new_link + closing))\
#                 .as_tokens
#         except UnknownSymbol:
#             return invocation.as_tokens
# 
#     def update_link(self, parser, link, invocation):
#         """To be over-ridden in sub classes"""
#         pass


import re
from flap.latex.macros.commons import Macro, UpdateLink
# along with Flap.  If not, see <http://www.gnu.org/licenses/>.
#




class Bibliography(UpdateLink):
    """
    Intercept the `\bibliography` directive
    """

    def __init__(self, flap):
        super().__init__(flap, "bibliography")

    def update_link(self, parser, link, invocation):
        return self._flap.update_link_to_bibliography(link, invocation)


class BibliographyStyle(UpdateLink):
    """
    Intercept the `\bibliographystyle` directive
    """

    def __init__(self, flap):
        super().__init__(flap, "bibliographystyle")

    def update_link(self, parser, link, invocation):
        return self._flap.update_link_to_bibliography_style(link, invocation)



# Path: flap/latex/macros/commons.py
# class Macro:
#     """
#     A LaTeX macro, including its name (e.g., 'point'), its signature
#     as a list of expected tokens (e.g., '(#1,#2)') and the text that
#     should replace it.
#     """
# 
#     def __init__(self, flap, name, signature, body):
#         self._flap = flap
#         self._name = name if not name.startswith("\\") else name[1:]
#         self._signature = signature or []
#         self._body = body or iter([])
#         self._called = False
#         self._requires_expansion = False
#         self.is_user_defined = False
# 
#     @property
#     def requires_expansion(self):
#         return self._requires_expansion
# 
#     @property
#     def was_called(self):
#         return self._called
# 
#     @property
#     def name(self):
#         return self._name
# 
#     def execute2(self, parser, invocation):
#         self._called = True
#         pass
# 
#     def rewrite2(self, parser, invocation):
#         return invocation.as_tokens
# 
#     def capture_invocation(self, parser, command):
#         invocation = Invocation(command)
#         self._capture_arguments(parser, invocation)
#         return invocation
# 
#     def _capture_arguments(self, parser, invocation):
#         for index, any_token in enumerate(self._signature):
#             if any_token.is_a_parameter:
#                 parameter = str(any_token)
#                 if index == len(self._signature) - 1:
#                     expression = parser.read.one()
#                     invocation.append_argument(parameter, expression)
#                     logger.debug("Arg '{}' is '{}'".format(
#                         any_token.as_text,
#                         "".join(t.as_text for t in expression)))
#                 else:
#                     next_token = self._signature[index + 1]
#                     value = parser.read.until_text(next_token.as_text)
#                     invocation.append_argument(parameter, value)
#                     logger.debug("Arg '{}' is '{}'".format(
#                         any_token.as_text,
#                         "".join(t.as_text for t in value)))
#             else:
#                 invocation.append(parser.read.text(str(any_token)))
# 
#     def expand(self, invocation):
#         # TODO: Remove, useless as the we don't substitute tokens into
#         # the body anymore
#         result = []
#         for any_token in self._body:
#             if any_token.is_a_parameter:
#                 result += invocation.argument(str(any_token))
#             else:
#                 result.append(any_token)
#         return result
# 
#     def __eq__(self, other):
#         if not isinstance(other, Macro):
#             return False
#         return self._name == other._name and \
#             self._signature == other._signature and \
#             self._body == other._body
# 
#     def __repr__(self):
#         signature, body = "", ""
#         if signature:
#             signature = "".join(map(str, self._signature))
#         if body:
#             body = "".join(map(str, self._body))
#         return r"\def" + self._name + signature + body
# 
# class UpdateLink(Macro):
# 
#     def __init__(self, flap, name):
#         super().__init__(flap, name, None, None)
# 
#     @staticmethod
#     def _capture_arguments(parser, invocation):
#         invocation.append_argument("options", parser.read.options())
#         logger.debug("Options = '%s'", invocation.argument_as_text("options"))
#         invocation.append_argument("link", parser.read.group())
# 
#     def execute2(self, parser, invocation):
#         pass
# 
#     def rewrite2(self, parser, invocation):
#         try:
#             link_tokens = invocation.argument("link")
#             link = parser.evaluate_as_text(invocation.argument("link"))
#             new_link = self.update_link(parser, link, invocation)
#             opening = str(link_tokens[0])
#             closing = str(link_tokens[-1])
#             return invocation\
#                 .substitute("link",
#                             parser._create.as_list(opening + new_link + closing))\
#                 .as_tokens
#         except UnknownSymbol:
#             return invocation.as_tokens
# 
#     def update_link(self, parser, link, invocation):
#         """To be over-ridden in sub classes"""
#         pass


# Path: flap/latex/macros/bibliography.py
import re
from flap.latex.macros.commons import Macro, UpdateLink

# along with Flap.  If not, see <http://www.gnu.org/licenses/>.
#




class Bibliography(UpdateLink):
    """
    Intercept the `\bibliography` directive
    """

    def __init__(self, flap):
        super().__init__(flap, "bibliography")

    def update_link(self, parser, link, invocation):
        return self._flap.update_link_to_bibliography(link, invocation)


class BibliographyStyle(UpdateLink):
    """
    Intercept the `\bibliographystyle` directive
    """

    def __init__(self, flap):
        super().__init__(flap, "bibliographystyle")

    def update_link(self, parser, link, invocation):
        return self._flap.update_link_to_bibliography_style(link, invocation)



class MakeIndex(Macro):