Ejemplo n.º 1
0
    def test_flags_ref_types(self):

        fix = ref.ExpandRefs(only_ref_types='ref')
        self.assertEqual(fix.ref_types, ['ref'])
        fix = ref.ExpandRefs(only_ref_types='cleveref')
        self.assertEqual(fix.ref_types, ['cleveref'])
        fix = ref.ExpandRefs(only_ref_types=['ref', 'ams-eqref'])
        self.assertEqual(fix.ref_types, ['ref', 'ams-eqref'])
        fix = ref.ExpandRefs(only_ref_types=set(['ref', 'ams-eqref']))
        self.assertEqual(set(fix.ref_types), set(['ref', 'ams-eqref']))
Ejemplo n.º 2
0
    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}
"""
        )
Ejemplo n.º 3
0
    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}
"""
        )
Ejemplo n.º 4
0
    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}
"""
        )
Ejemplo n.º 5
0
    def test_crefs_with_prefixes(self):
        
        latex = r"""
\documentclass[11pt]{article}

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

\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
Try \cref*{A-lemma:test}; \cref*{B-eq:hi}; \cref{B-eq:hi,lemma:test2}; \cref{lemma:test2}
Also \crefrange*{A-eq:hello}{B-eq:hi}; \cpagerefrange{A-eq:hello}{B-eq:hi}

Here is a lemma:
\begin{lemma}
  \label{A-lemma:test}
  Test lemma. 
\end{lemma}
Here is an equation
\begin{equation}
  \label{A-eq:hello}
  a + b = c \ .
\end{equation}
and another:
\begin{equation}
  \label{B-eq:hi}
  x = y\ .
\end{equation}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = ref.ExpandRefs(expand_only_prefixes=['A-','B-'], debug_latex_output=True)
        fix._get_doc_preamble = fix._get_doc_preamble_recomposed
        fix._get_auxfile_contents = lambda: hyperref_aux_preamble + r"""
\newlabel{A-lemma:test}{{1}{1}{}{lemma.1}{}}
\newlabel{A-lemma:test@cref}{{[lemma][1][]1}{1}}
\newlabel{A-eq:hello}{{1}{1}{}{equation.0.1}{}}
\newlabel{A-eq:hello@cref}{{[equation][1][]1}{1}}
\newlabel{B-eq:hi}{{2}{1}{}{equation.0.2}{}}
\newlabel{B-eq:hi@cref}{{[equation][2][]2}{1}}
\newlabel{lemma:test2}{{2}{1}{}{lemma.2}{}}
\newlabel{lemma:test2@cref}{{[lemma][2][]2}{1}}
"""
        lpp.install_fix( fix )

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

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

\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
Try lemma\protect \nobreakspace  1; eq.\protect \nobreakspace  \protect \textup  {(2)}; \cref{B-eq:hi,lemma:test2}; \cref{lemma:test2}
Also eqs.\protect \nobreakspace  \protect \textup  {(1)} to\protect \nobreakspace  \protect \textup  {(2)}; pages\protect \nobreakspace  \protect \hyperlink {equation.0.1}{1} to\protect \nobreakspace  \protect \hyperlink {equation.0.2}{1}

Here is a lemma:
\begin{lemma}
  \label{A-lemma:test}
  Test lemma. 
\end{lemma}
Here is an equation
\begin{equation}
  \label{A-eq:hello}
  a + b = c \ .
\end{equation}
and another:
\begin{equation}
  \label{B-eq:hi}
  x = y\ .
\end{equation}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""
        )
Ejemplo n.º 6
0
    def test_simple_namecref(self):
        
        latex = r"""
\documentclass[11pt]{article}

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

\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

The proof of the \namecref{lemma:test2} is easy.
\nameCrefs{lemma:test2} like these are simple to prove.
``\nameCref{eq:hello}'' should work too (we'll add more
\namecrefs{eq:hello} in the future), and so should
``\lcnamecref{eq:hello}'' and ``\lcnamecrefs{eq:hello}.''

Here is a lemma:
\begin{lemma}
  \label{lemma:test}
  Test lemma. 
\end{lemma}
Here is an equation
\begin{equation}
  \label{eq:hello}
  a + b = c \ .
\end{equation}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = ref.ExpandRefs(only_ref_types=('cleveref',), debug_latex_output=True)
        fix._get_doc_preamble = fix._get_doc_preamble_recomposed
        fix._get_auxfile_contents = lambda: hyperref_aux_preamble + r"""
\newlabel{lemma:test}{{1}{1}{}{lemma.1}{}}
\newlabel{lemma:test@cref}{{[lemma][1][]1}{1}}
\newlabel{eq:hello}{{1}{1}{}{equation.0.1}{}}
\newlabel{eq:hello@cref}{{[equation][1][]1}{1}}
\newlabel{lemma:test2}{{2}{1}{}{lemma.2}{}}
\newlabel{lemma:test2@cref}{{[lemma][2][]2}{1}}
"""
        lpp.install_fix( fix )

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

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

\usepackage{hyperref}


\begin{document}

The proof of the lemma is easy.
Lemmas like these are simple to prove.
``Equation'' should work too (we'll add more
eqs. in the future), and so should
``\protect \MakeLowercase Equation'' and ``\protect \MakeLowercase Equations.''

Here is a lemma:
\begin{lemma}
  \label{lemma:test}
  Test lemma. 
\end{lemma}
Here is an equation
\begin{equation}
  \label{eq:hello}
  a + b = c \ .
\end{equation}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""
        )
Ejemplo n.º 7
0
    def test_simple_crefrange_nolink(self):
        
        latex = r"""
\documentclass[11pt]{article}

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

\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
Ranges should work, too, like this:
\crefrange{lemma:test}{lemma:test2} on
\cpagerefrange{lemma:test}{lemma:test2}, as well as their
capitalized versions: \Crefrange{lemma:test}{lemma:test2};
\Cpagerefrange{lemma:test}{lemma:test2}.

Here is a lemma:
\begin{lemma}
  \label{lemma:test}
  Test lemma. 
\end{lemma}
Here is an equation
\begin{equation}
  \label{eq:hello}
  a + b = c \ .
\end{equation}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = ref.ExpandRefs(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{lemma:test}{{1}{1}{}{lemma.1}{}}
\newlabel{lemma:test@cref}{{[lemma][1][]1}{1}}
\newlabel{lemma:test2}{{2}{1}{}{lemma.2}{}}
\newlabel{lemma:test2@cref}{{[lemma][2][]2}{1}}
"""
        lpp.install_fix( fix )

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

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

\usepackage{hyperref}


\begin{document}
Ranges should work, too, like this:
lemmas\protect \nobreakspace  1 to\protect \nobreakspace  2 on
pages\protect \nobreakspace  1 to\protect \nobreakspace  1, as well as their
capitalized versions: Lemmas\protect \nobreakspace  1 to\protect \nobreakspace  2;
Pages\protect \nobreakspace  1 to\protect \nobreakspace  1.

Here is a lemma:
\begin{lemma}
  \label{lemma:test}
  Test lemma. 
\end{lemma}
Here is an equation
\begin{equation}
  \label{eq:hello}
  a + b = c \ .
\end{equation}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""
        )
Ejemplo n.º 8
0
    def test_simple_cref_nohyperrefloaded(self):
        
        latex = r"""
\documentclass[11pt]{article}

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

\usepackage{cleveref}

\begin{document}
A reference to \cref{lemma:test}. \Cref{lemma:test2} on
 \cpageref{lemma:test2} is nice, too. \Cpageref{lemma:test2}
is what that was.

Here is a lemma:
\begin{lemma}
  \label{lemma:test}
  Test lemma. 
\end{lemma}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""

        lpp = helpers.MockLPP()
        fix = ref.ExpandRefs(make_hyperlinks=True, debug_latex_output=True)
        fix._get_doc_preamble = fix._get_doc_preamble_recomposed
        fix._get_auxfile_contents = lambda: r"""
\newlabel{lemma:test}{{1}{1}}
\newlabel{lemma:test@cref}{{[lemma][1][]1}{1}}
\newlabel{lemma:test2}{{2}{1}}
\newlabel{lemma:test2@cref}{{[lemma][2][]2}{1}}
"""
        lpp.install_fix( fix )

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

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



\begin{document}
A reference to lemma\protect \nobreakspace  1. Lemma\protect \nobreakspace  2 on
 page\protect \nobreakspace  1 is nice, too. Page\protect \nobreakspace  1
is what that was.

Here is a lemma:
\begin{lemma}
  \label{lemma:test}
  Test lemma. 
\end{lemma}
And here is another lemma:
\begin{lemma}
  \label{lemma:test2}
  Another test lemma.
\end{lemma}
\end{document}
"""
        )