コード例 #1
0
    def test_simple_1(self):

        lpp = helpers.MockLPP()
        lpp.install_fix(
            macro_subst.Subst(macros={
                'abc':
                r'\textbf{ABC}',
                'xyz':
                dict(argspec='*[{',
                     repl=r'\chapter%(1)s[{Opt title: %(2)s}]{Title: %(3)s}')
            },
                              environments={'equation*': r'\[%(body)s\]'}))

        self.assertEqual(
            lpp.execute(r"""
Hello guys.  Just testin': \abc.

\xyz*{Yo}

\begin{equation*}
  \alpha = \beta
\end{equation*}

\xyz[Hey]{Ya}
"""), r"""
Hello guys.  Just testin': \textbf{ABC}.

\chapter*[{Opt title: }]{Title: Yo}

\[
  \alpha = \beta
\]

\chapter[{Opt title: Hey}]{Title: Ya}
""")
コード例 #2
0
    def test_no_collapse(self):

        latex = r"""Line with % comment here

\begin{stuff}
    % line comment on its own
  % and a second line
  stuff...
\end{stuff}

Also a \itshape% comment after a macro
% and also a second line
some italic text."""

        lpp = helpers.MockLPP()
        lpp.install_fix(comments.RemoveComments(collapse=False))

        self.assertEqual(
            lpp.execute(latex), r"""Line with %

\begin{stuff}
    %
  %
  stuff...
\end{stuff}

Also a \itshape%
%
some italic text.""")
コード例 #3
0
    def test_preprocess_00b(self):
        class MyFix(BaseFix):
            def fix_node(self, n, **kwargs):
                if n.isNodeType(latexwalker.LatexMacroNode
                                ) and n.macroname == 'testmacro':
                    return r'\newmacro {}'
                return None

        latex = r"""Test: \testmacro% a comment
Text and \`accent and \textbf{bold text} and $\vec b$ more stuff for Fran\c cois
\begin{enumerate}[(i)]
\item Hi there!  % here goes a comment
 \item[a] Hello!  @@@
     \end{enumerate}
Indeed thanks to \cite[Lemma 3]{Author}, we know that...
Also: {\itshape some italic text}."""

        lpp = helpers.MockLPP()
        myfix = MyFix()
        lpp.install_fix(myfix)

        lw = lpp.make_latex_walker(latex)
        nodelist = lw.get_latex_nodes()[0]

        newnodelist = myfix.preprocess(nodelist[0:3])
        self.assertEqual((newnodelist[0], newnodelist[3]),
                         (nodelist[0], nodelist[2]))
        self.assertEqual(
            (newnodelist[1].macroname, newnodelist[1].nodeargd.argnlist,
             newnodelist[1].macro_post_space, newnodelist[2].nodelist),
            (r'newmacro', [], ' ', []))
コード例 #4
0
    def test_preprocess_01(self):
        class MyFix(BaseFix):
            def fix_node(self, n, **kwargs):
                if n.isNodeType(latexwalker.LatexMacroNode
                                ) and n.macroname == 'testmacro':
                    return r'\newmacro {}'
                return None

        latex = r"""Test: \testmacro% a comment"""

        lpp = helpers.MockLPP()
        myfix = MyFix()
        lpp.install_fix(myfix)

        lw = lpp.make_latex_walker(latex)
        nodelist = lw.get_latex_nodes()[0]

        newnodelist = myfix.preprocess(nodelist)
        self.assertEqual(len(newnodelist), 4)
        self.assertEqual((newnodelist[0], newnodelist[3]),
                         (nodelist[0], nodelist[2]))
        self.assertEqual(
            (newnodelist[1].macroname, newnodelist[1].nodeargd.argnlist,
             newnodelist[1].macro_post_space, newnodelist[2].nodelist),
            (r'newmacro', [], ' ', []))
コード例 #5
0
    def test_preprocess_macroarg(self):
        class MyFix(BaseFix):
            def fix_node(self, n, **kwargs):
                if n.isNodeType(
                        latexwalker.LatexMacroNode) and n.macroname == 'hello':
                    return r'Hello !'
                return None

        latex = r"""\textbf\hello"""

        lpp = helpers.MockLPP()
        myfix = MyFix()
        lpp.install_fix(myfix)

        lw = lpp.make_latex_walker(latex)
        nodelist = lw.get_latex_nodes()[0]

        newnodelist = myfix.preprocess(nodelist)
        self.assertEqual(len(newnodelist), 1)
        self.assertTrue(newnodelist[0].isNodeType(latexwalker.LatexMacroNode))
        m = newnodelist[0]
        self.assertEqual(len(m.nodeargd.argnlist), 1)
        g = m.nodeargd.argnlist[0]
        self.assertTrue(g.isNodeType(latexwalker.LatexGroupNode))
        self.assertEqual(len(g.nodelist), 1)
        c = g.nodelist[0]
        self.assertTrue(c.isNodeType(latexwalker.LatexCharsNode))
        self.assertEqual(c.chars, "Hello !")
コード例 #6
0
    def test_simple_1b(self):

        # test that collapsing comments do respect the post-space of the last
        # comment

        latex = r"""Line with % comment here

\begin{stuff}
    % line comment on its own
  % and a second line
  stuff...
\end{stuff}

Also a \itshape% comment after a macro
% and also a second line
some italic text."""

        lpp = helpers.MockLPP()
        lpp.install_fix(comments.RemoveComments())

        self.assertEqual(
            lpp.execute(latex), r"""Line with %

\begin{stuff}
    %
  stuff...
\end{stuff}

Also a \itshape%
some italic text.""")
コード例 #7
0
    def test_preprocess_recursively(self):
        class MyFix(BaseFix):
            def fix_node(self, n, **kwargs):
                if n.isNodeType(latexwalker.LatexMacroNode
                                ) and n.macroname == 'textbf':
                    if n.nodeargd is None or not n.nodeargd.argnlist \
                       or not n.nodeargd.argnlist[0]:
                        return None
                    return r'\myboldtext {' \
                        + self.preprocess_contents_latex(n.nodeargd.argnlist[0]) + '}'
                if n.isNodeType(latexwalker.LatexEnvironmentNode) \
                   and n.environmentname == 'enumerate':
                    if n.nodeargd is None or not n.nodeargd.argnlist or not n.nodeargd.argnlist[
                            0]:
                        return r'\mystuff{' + self.preprocess_contents_latex(
                            n.nodelist) + '}'
                    return r'\mystuff[' + self.preprocess_arg_latex(n, 0) \
                        + ']{' + self.preprocess_latex(n.nodelist) + '}'
                return None

        latex = r"""
\begin{enumerate}[\textbf{recursive} replacement]text text\end{enumerate}"""
        lpp = helpers.MockLPP()
        myfix = MyFix()
        lpp.install_fix(myfix)
        lw = lpp.make_latex_walker(latex)
        nodelist = lw.get_latex_nodes()[0]
        newnodelist = myfix.preprocess(nodelist)
        newlatex = "".join(nn.to_latex() for nn in newnodelist)
        self.assertEqual(
            newlatex, r"""
\mystuff[\myboldtext {recursive} replacement]{text text}""")
コード例 #8
0
    def test_preprocess_macrospace(self):
        class MyFix(BaseFix):
            def fix_node(self, n, **kwargs):
                if n.isNodeType(
                        latexwalker.LatexMacroNode) and n.macroname == 'rho':
                    return r'\hat\sigma'
                return None

        latex = r"""The projected state $P_k\rho  P_{k'}$"""

        lpp = helpers.MockLPP()
        myfix = MyFix()
        lpp.install_fix(myfix)

        lw = lpp.make_latex_walker(latex)
        nodelist = lw.get_latex_nodes()[0]

        newnodelist = myfix.preprocess(nodelist)
        self.assertEqual(len(newnodelist), 2)
        self.assertEqual(newnodelist[0], nodelist[0])
        self.assertTrue(newnodelist[1].isNodeType(latexwalker.LatexMathNode))
        self.assertEqual(len(newnodelist[1].nodelist), 4)
        self.assertEqual(
            (newnodelist[1].nodelist[0], newnodelist[1].nodelist[2]),
            (nodelist[1].nodelist[0], nodelist[1].nodelist[2]))
        m1 = newnodelist[1].nodelist[1]
        self.assertEqual((m1.macroname, m1.macro_post_space,
                          m1.nodeargd.argnlist[0].macroname,
                          m1.nodeargd.argnlist[0].macro_post_space),
                         (r'hat', '', r'sigma', ' '))
コード例 #9
0
    def test_simple(self):

        lpp = helpers.MockLPP()
        lpp.install_fix(usepackage.RemovePkgs(['phfparen', 'mymacros']))

        self.assertEqual(
            lpp.execute(r"""
\documentclass{article}

\usepackage{amsmath}
\usepackage{phfparen}
\usepackage[someoptions,moreoptions]{mymacros}%

\begin{document}
Hello world.
\end{document}
"""), r"""
\documentclass{article}

\usepackage{amsmath}

%

\begin{document}
Hello world.
\end{document}
""")
コード例 #10
0
    def test_simple(self):

        mock_files = {
            # list of files that "exist"
            "mymacros.sty": "%test",
            "cleveref.sty": "%test",
        }
        usepackage.os_path = helpers.FakeOsPath(list(mock_files.keys()))

        lpp = helpers.MockLPP(mock_files)
        lpp.install_fix(usepackage.CopyLocalPkgs())

        lpp.execute(r"""
\documentclass{article}

\usepackage{amsmath}
\usepackage{phfparen}
\usepackage[someoptions,moreoptions]{mymacros}%
\usepackage{cleveref}

\begin{document}
Hello world.
\end{document}
""")
        self.assertEqual(lpp.copied_files, [
            ('mymacros.sty', '/TESTOUT/mymacros.sty'),
            ('cleveref.sty', '/TESTOUT/cleveref.sty'),
        ])
コード例 #11
0
    def test_simple(self):
        
        latex = r"""
\documentclass[11pt]{article}

\newcommand{\a}{Albert Einstein}
\newcommand\max[1]{Max #1}

\begin{document}
\a{} and \max{Planck} both thought a lot about quantum mechanics.
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = newcommand.Expand(leave_newcommand=True)
        lpp.install_fix( fix )

        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}

\newcommand{\a}{Albert Einstein}
\newcommand\max[1]{Max #1}

\begin{document}
Albert Einstein{} and Max Planck both thought a lot about quantum mechanics.
\end{document}
"""
        )
コード例 #12
0
    def test_macro_blacklist(self):
        latex = r"""
\documentclass[11pt]{article}

\newcommand{\a}{Albert Einstein}
\newcommand\b{Bbbb}
\newcommand\bob{Bobbby}
\newcommand\max[1]{Max #1}
\renewcommand\thepage{\roman{page}}

\begin{document}
\a{} and \max{Planck} both thought a lot about quantum mechanics. Some B's by \bob: \b.
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = newcommand.Expand(leave_newcommand=False, macro_blacklist_patterns=[r'b$', r'^the'])
        lpp.install_fix( fix )

        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}


\newcommand\b{Bbbb}
\newcommand\bob{Bobbby}

\renewcommand\thepage{\roman{page}}

\begin{document}
Albert Einstein{} and Max Planck both thought a lot about quantum mechanics. Some B's by \bob: \b.
\end{document}
"""
        )
コード例 #13
0
    def test_newcommand_cmds(self):
        latex = r"""
\documentclass[11pt]{article}

\newcommand{\a}{Albert Einstein}
\renewcommand\thepage{$-$ \roman{page} $-$}
\providecommand\max[1]{Max #1}

\begin{document}
\a{} and \max{Planck} both thought a lot about quantum mechanics.
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = newcommand.Expand(newcommand_cmds=['newcommand', 'providecommand'],
                                leave_newcommand=False)
        lpp.install_fix( fix )

        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}


\renewcommand\thepage{$-$ \roman{page} $-$}


\begin{document}
Albert Einstein{} and Max Planck both thought a lot about quantum mechanics.
\end{document}
"""
        )
コード例 #14
0
    def test_simple(self):

        latex = r"""
\bibalias{alias1}{target1}
\bibalias{alias2}{target2}
\begin{document}
Some text~\cite{alias1,target3} and see also~\citep{alias2}.
\bibliography{mybib1,bib2}
\end{document}
"""

        lpp = helpers.MockLPP(
            mock_files={
                'TESTDOC.bbl':
                r"\relax\bibdata{XYZ}\bibcite{mybib1}{24}"  # etc. this is random stuff here
            })
        lpp.install_fix(bib.CopyAndInputBbl())
        lpp.install_fix(bib.ApplyAliases())

        self.assertEqual(
            lpp.execute(latex), r"""


\begin{document}
Some text~\cite{target1,target3} and see also~\citep{target2}.
\input{TESTMAIN.bbl}
\end{document}
""")

        self.assertEqual(lpp.copied_files,
                         [('TESTDOC.bbl', '/TESTOUT/TESTMAIN.bbl')])
コード例 #15
0
    def test_recursive(self):

        lpp = helpers.MockLPP()
        lpp.install_fix(
            macro_subst.Subst(macros={
                'ket':
                dict(argspec='{', repl=r'\lvert{%(1)s}\rangle'),
                'rhostate':
                r'\hat\rho',
            }, ))

        self.assertEqual(lpp.execute(r"""\ket\rhostate"""),
                         r"""\lvert{\hat\rho}\rangle""")
コード例 #16
0
ファイル: test_fixes_ref.py プロジェクト: psg-mit/latexpp
    def test_simple_eqref_with_hyperref(self):
        
        latex = r"""
\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{lemma}{Lemma}

\usepackage{hyperref}

\begin{document}
Equation~\eqref{eq:test}:
\begin{equation}
  \label{eq:test}
  a + b = c\ .
\end{equation}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = ref.ExpandRefs(only_ref_types='ams-eqref', debug_latex_output=True)
        fix._get_doc_preamble = fix._get_doc_preamble_recomposed
        fix._get_auxfile_contents = lambda: hyperref_aux_preamble + r"""
\newlabel{eq:test}{{1}{1}{}{equation.0.1}{}}
"""
        lpp.install_fix( fix )

        # NOTE: KEEP \protect's in output, because the substitution might happen
        # somewhere fragile.
        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{lemma}{Lemma}

\usepackage{hyperref}

\begin{document}
Equation~\protect \textup  {\mathsurround \z@ \protect \normalfont  (\ignorespaces \protect \hyperref [eq:test]{1}\unskip \@@italiccorr )}:
\begin{equation}
  \label{eq:test}
  a + b = c\ .
\end{equation}
\end{document}
"""
        )
コード例 #17
0
ファイル: test_fixes_input.py プロジェクト: psg-mit/latexpp
    def test_simple(self):

        input.os_path = helpers.FakeOsPath([
            # list of files that "exist"
            'chapter1.tex',
            'chapter2.latex',
        ])

        ei = input.EvalInput()

        ei._read_file_contents = lambda fn: {
            'chapter1.tex':
            r"""
\chapter[first]{Chapter uno}
This is the \emph{contents} of ``Chapter 1.''
""",
            'chapter2.latex':
            r"""\chapter{The second of chapters}
Here is the \textbf{contents} of ``Chapter 2!''
""",
        }.get(fn)

        lpp = helpers.MockLPP()
        lpp.install_fix(ei)

        self.assertEqual(
            lpp.execute(r"""
Hello, this might be an introduction:
\[ a + b = c\ . \]

\input{chapter1.tex}

\include{chapter2}
"""), r"""
Hello, this might be an introduction:
\[ a + b = c\ . \]


\chapter[first]{Chapter uno}
This is the \emph{contents} of ``Chapter 1.''


\clearpage
\chapter{The second of chapters}
Here is the \textbf{contents} of ``Chapter 2!''

""")

        self.assertEqual(lpp.copied_files, [])
コード例 #18
0
ファイル: test_fixes_deps.py プロジェクト: psg-mit/latexpp
    def test_simple(self):
        
        lpp = helpers.MockLPP()
        lpp.install_fix( deps.CopyFiles(['a.sty', 'b.clo', 'fig/myfig.jpg']) )

        lpp.execute("")

        self.assertEqual(
            lpp.copied_files,
            [
                ('a.sty', '/TESTOUT/a.sty'),
                ('b.clo', '/TESTOUT/b.clo'),
                ('fig/myfig.jpg', '/TESTOUT/fig/myfig.jpg'),
            ]
        )
コード例 #19
0
ファイル: test_fixes_ref.py プロジェクト: psg-mit/latexpp
    def test_simple_ref_with_hyperref_nolink(self):
        
        latex = r"""
\documentclass[11pt]{article}

\usepackage{amsthm}
\newtheorem{lemma}{Lemma}

\usepackage{hyperref}

\begin{document}
Equation~(\ref{eq:test}) [Eq.~(\ref*{eq:test}) without link]:
\begin{equation}
  \label{eq:test}
  a + b = c\ .
\end{equation}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = ref.ExpandRefs(only_ref_types='ref', make_hyperlinks=False, debug_latex_output=True)
        fix._get_doc_preamble = fix._get_doc_preamble_recomposed
        fix._get_auxfile_contents = lambda: hyperref_aux_preamble + r"""
\newlabel{eq:test}{{1}{1}{}{equation.0.1}{}}
"""
        lpp.install_fix( fix )

        # NOTE: KEEP \protect's in output, because the substitution might happen
        # somewhere fragile.
        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}

\usepackage{amsthm}
\newtheorem{lemma}{Lemma}

\usepackage{hyperref}

\begin{document}
Equation~(1) [Eq.~(1) without link]:
\begin{equation}
  \label{eq:test}
  a + b = c\ .
\end{equation}
\end{document}
"""
        )
コード例 #20
0
    def test_preprocess_recursively_2(self):
        class MyFix(BaseFix):
            def fix_node(self, n, **kwargs):
                if n.isNodeType(latexwalker.LatexMacroNode
                                ) and n.macroname == 'textbf':
                    if n.nodeargd is None or not n.nodeargd.argnlist \
                       or not n.nodeargd.argnlist[0]:
                        return None
                    return r'\myboldtext {' + self.preprocess_arg_latex(
                        n, 0) + '}'
                if n.isNodeType(latexwalker.LatexEnvironmentNode) \
                   and n.environmentname == 'enumerate':
                    if n.nodeargd is None or not n.nodeargd.argnlist or not n.nodeargd.argnlist[
                            0]:
                        return r'\mystuff{' + self.preprocess_latex(
                            n.nodelist) + '}'
                    return r'\mystuff[' + self.preprocess_arg_latex(n, 0) \
                        + ']{' + self.preprocess_latex(n.nodelist) + '}'
                return None

        latex = r"""
\begin{enumerate}
\item Some \textbf{BOLD \textbf{text} AND MORE} and more.
\item And a sublist:
  \begin{enumerate}[\textbf{recursive} replacement]
  \item[\textbf{in \textbf{macro} optional argument}]
  \end{enumerate}
\item And in math mode $a\textbf{v} = \textbf{w+\textbf{z}+x}$
\end{enumerate}
"""
        lpp = helpers.MockLPP()
        myfix = MyFix()
        lpp.install_fix(myfix)
        lw = lpp.make_latex_walker(latex)
        nodelist = lw.get_latex_nodes()[0]
        newnodelist = myfix.preprocess(nodelist)
        newlatex = "".join(nn.to_latex() for nn in newnodelist)
        self.assertEqual(
            newlatex, r"""
\mystuff{
\item Some \myboldtext {BOLD \myboldtext {text} AND MORE} and more.
\item And a sublist:
  \mystuff[\myboldtext {recursive} replacement]{
  \item[\myboldtext {in \myboldtext {macro} optional argument}]
  }
\item And in math mode $a\myboldtext {v} = \myboldtext {w+\myboldtext {z}+x}$
}
""")
コード例 #21
0
ファイル: test_fixes_ref.py プロジェクト: psg-mit/latexpp
    def test_simple_ref(self):
        
        latex = r"""
\documentclass[11pt]{article}

\usepackage{amsthm}
\newtheorem{lemma}{Lemma}

\begin{document}
Equation~(\ref{eq:test}) on page~\pageref{eq:test} reads:
\begin{equation}
  \label{eq:test}
  a + b = c\ .
\end{equation}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = ref.ExpandRefs(only_ref_types='ref', debug_latex_output=True)
        fix._get_doc_preamble = fix._get_doc_preamble_recomposed
        fix._get_auxfile_contents = lambda: r"""
\relax 
\newlabel{eq:test}{{1}{1}}
"""
        lpp.install_fix( fix )

        # NOTE: KEEP \protect's in output, because the substitution might happen
        # somewhere fragile.
        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}

\usepackage{amsthm}
\newtheorem{lemma}{Lemma}

\begin{document}
Equation~(1) on page~1 reads:
\begin{equation}
  \label{eq:test}
  a + b = c\ .
\end{equation}
\end{document}
"""
        )
コード例 #22
0
    def test_newenvironment(self):
        latex = r"""
\documentclass[11pt]{article}

\newcommand\Albert{Albert E.}
\newenvironment{testenviron}[2][x]{\texttt{testenviron<#1>{#2}}}{\texttt{endtestenviron}}

\begin{document}
Hello.
\begin{testenviron}\textasciitilde
Environment \textbf{body}, with an equation:
\begin{equation}
   x = y + z\ .
\end{equation}
(Not by \Albert.)
\end{testenviron}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = newcommand.Expand(newcommand_cmds=['newenvironment'])
        lpp.install_fix( fix )

        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}

\newcommand\Albert{Albert E.}


\begin{document}
Hello.
{\texttt{testenviron<x>{\textasciitilde
}}Environment \textbf{body}, with an equation:
\begin{equation}
   x = y + z\ .
\end{equation}
(Not by \Albert.)
\texttt{endtestenviron}}
\end{document}
"""
        )
コード例 #23
0
    def test_leave_percent(self):

        latex = r"""Line with % comment here
some text.
% line comment on its own
% and a second line

Also a \itshape% comment after a macro
% and also a second line
some italic text."""

        lpp = helpers.MockLPP()
        lpp.install_fix(comments.RemoveComments(leave_percent=False))

        self.assertEqual(
            lpp.execute(latex), r"""Line with some text.


Also a \itshape some italic text.""")
コード例 #24
0
    def test_simple_2(self):

        figures.os_path = helpers.FakeOsPath([
            # list of files that "exist"
            'fig/intro.png',
            'my_diagram.jpg',
            'v088338-1993.out.eps',
            'fignew/results schematic.pdf',
            'fignew/results schematic 2.jpg'
        ])
            
        
        lpp = helpers.MockLPP()
        lpp.install_fix( figures.CopyAndRenameFigs(
            start_fig_counter=9,
            fig_rename='fig/{fig_counter}/{orig_fig_basename}{fig_ext}',
            
        ) )

        self.assertEqual(
            lpp.execute(r"""
                \includegraphics[width=\textwidth]{fig/intro}
                \includegraphics[width=\textwidth]{my_diagram.jpg}
                \includegraphics{fignew/results schematic}
                \includegraphics{v088338-1993.out}
            """),
            r"""
                \includegraphics[width=\textwidth]{fig/9/intro.png}
                \includegraphics[width=\textwidth]{fig/10/my_diagram.jpg}
                \includegraphics{fig/11/results schematic.pdf}
                \includegraphics{fig/12/v088338-1993.out.eps}
            """
        )

        self.assertEqual(
            lpp.copied_files,
            [
                ('fig/intro.png', '/TESTOUT/fig/9/intro.png'),
                ('my_diagram.jpg', '/TESTOUT/fig/10/my_diagram.jpg'),
                ('fignew/results schematic.pdf', '/TESTOUT/fig/11/results schematic.pdf'),
                ('v088338-1993.out.eps', '/TESTOUT/fig/12/v088338-1993.out.eps'),
            ]
        )
コード例 #25
0
ファイル: test_fixes_input.py プロジェクト: psg-mit/latexpp
    def test_simple(self):

        input.os_path = helpers.FakeOsPath([
            # list of files that "exist"
            'chapter1.tex',
            'chapter2.latex',
        ])

        mock_files = {
            'chapter1.tex':
            r"""
\chapter[first]{Chapter uno}
This is the \emph{contents} of ``Chapter 1.''
""",
            'chapter2.latex':
            r"""\chapter{The second of chapters}
Here is the \textbf{contents} of ``Chapter 2!''
""",
        }

        lpp = helpers.MockLPP(mock_files=mock_files)
        lpp.install_fix(input.CopyInputDeps())

        self.assertEqual(
            lpp.execute(r"""
Hello, this might be an introduction:
\[ a + b = c\ . \]

\input{chapter1.tex}

\include{chapter2}
"""), r"""
Hello, this might be an introduction:
\[ a + b = c\ . \]

\input{chapter1.tex}

\include{chapter2}
""")  # no change

        self.assertEqual(lpp.wrote_executed_files, mock_files)
コード例 #26
0
    def test_environment_blacklist(self):
        latex = r"""
\documentclass[11pt]{article}

\newenvironment{testenviron}[2][x]{\texttt{testenviron<#1>{#2}}}{\texttt{endtestenviron}}
\newenvironment{minienviron}{begin}{end}

\begin{document}
Hello.
\begin{testenviron}{Z}
Environment \textbf{body}, with an inner environment:
\begin{minienviron}
Hi!
\end{minienviron}
\end{testenviron}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = newcommand.Expand(environment_blacklist_patterns=[r'm([a-z])n\1'])
        lpp.install_fix( fix )

        self.assertEqual(
            lpp.execute(latex),
            r"""
\documentclass[11pt]{article}


\newenvironment{minienviron}{begin}{end}

\begin{document}
Hello.
{\texttt{testenviron<x>{Z}}
Environment \textbf{body}, with an inner environment:
\begin{minienviron}
Hi!
\end{minienviron}
\texttt{endtestenviron}}
\end{document}
"""
        )
コード例 #27
0
    def test_simple_1(self):

        latex = r"""Line with % comment here

% line comment on its own
% and a second line

Also a \itshape% comment after a macro
% and also a second line
some italic text."""

        lpp = helpers.MockLPP()
        lpp.install_fix(comments.RemoveComments())

        self.assertEqual(
            lpp.execute(latex), r"""Line with %

%

Also a \itshape%
some italic text.""")
コード例 #28
0
    def test_simple(self):

        lpp = helpers.MockLPP()
        lpp.install_fix(
            preamble.AddPreamble(preamble=r"""
% use this package:
\usepackage{mycoolpackage}

% also keep these definitions:
\newcommand\hello[2][world]{Hello #1. #2}
"""))

        self.assertEqual(
            lpp.execute(r"""
\documentclass{article}

\usepackage{amsmath}

\begin{document}
Hello world.
\end{document}
"""), r"""
\documentclass{article}

\usepackage{amsmath}


%%%

% use this package:
\usepackage{mycoolpackage}

% also keep these definitions:
\newcommand\hello[2][world]{Hello #1. #2}

%%%
\begin{document}
Hello world.
\end{document}
""")
コード例 #29
0
    def test_simple_1(self):

        figures.os_path = helpers.FakeOsPath([
            # list of files that "exist"
            'fig/intro.png',
            'my_diagram.jpg',
            'v088338-1993.out.eps',
            'fignew/results schematic.pdf',
            'fignew/results schematic 2.jpg'
        ])
        
        lpp = helpers.MockLPP()
        lpp.install_fix( figures.CopyAndRenameFigs() )

        self.assertEqual(
            lpp.execute(r"""
                \includegraphics[width=\textwidth]{fig/intro}
                \includegraphics[width=\textwidth]{my_diagram.jpg}
                \includegraphics{fignew/results schematic}
                \includegraphics{v088338-1993.out}
            """),
            r"""
                \includegraphics[width=\textwidth]{fig-01.png}
                \includegraphics[width=\textwidth]{fig-02.jpg}
                \includegraphics{fig-03.pdf}
                \includegraphics{fig-04.eps}
            """
        )

        self.assertEqual(
            lpp.copied_files,
            [
                ('fig/intro.png', '/TESTOUT/fig-01.png'),
                ('my_diagram.jpg', '/TESTOUT/fig-02.jpg'),
                ('fignew/results schematic.pdf', '/TESTOUT/fig-03.pdf'),
                ('v088338-1993.out.eps', '/TESTOUT/fig-04.eps'),
            ]
        )
コード例 #30
0
    def test_preprocess_recursively_3(self):
        class MyFix(BaseFix):
            def fix_node(self, n, **kwargs):
                if n.isNodeType(latexwalker.LatexMacroNode):
                    #print("Try fix ", n)
                    if n.macroname == 'ket':
                        if n.nodeargd is None or not n.nodeargd.argnlist \
                           or not n.nodeargd.argnlist[0]:
                            return None
                        return r'| {' + self.preprocess_arg_latex(
                            n, 0) + r'} \rangle'
                    if n.macroname == r'rhostate':
                        return r'\hat\rho'
                return None

        latex = r"""\ket\rhostate"""
        lpp = helpers.MockLPP()
        myfix = MyFix()
        lpp.install_fix(myfix)
        lw = lpp.make_latex_walker(latex)
        nodelist = lw.get_latex_nodes()[0]
        newnodelist = myfix.preprocess(nodelist)
        newlatex = "".join(nn.to_latex() for nn in newnodelist)
        self.assertEqual(newlatex, r"""| {\hat\rho} \rangle""")