def test_wrong_index(self):
        with self.assertRaises(ValueError) as cm:
            generate_manual_caption('foo', 'wrong')

        self.assertEqual(
            str(cm.exception),
            'Environment must be one of "table", "figure". Got "wrong".')
 def test_figure_caption(self):
     latex = generate_manual_caption('The Caption', 'figure')
     self.assertIn(r'\addtocounter{figure}{1}', latex)
     self.assertIn(r'\addcontentsline{lof}{figure}', latex)
     self.assertIn(r'\ignorespaces The Caption', latex)
     self.assertIn(r'Figure \thechapter.\arabic{figure}: The Caption',
                   latex)
 def test_table_caption(self):
     latex = generate_manual_caption('The Caption', 'table')
     self.assertIn(r'\addtocounter{table}{1}', latex)
     self.assertIn(r'\addcontentsline{lot}{table}', latex)
     self.assertIn(r'\ignorespaces The Caption', latex)
     self.assertIn(r'Table \thechapter.\arabic{table}: The Caption',
                   latex)
Example #4
0
    def _extend_latex_with_caption(self, latex, caption, floatable):
        if not caption:
            return latex

        caption = self.layout.get_converter().convert(caption)
        if floatable:
            return '%s\n\\caption{%s}' % (latex, caption)

        else:
            return '%s\n%s' % (latex, generate_manual_caption(
                caption, 'figure'))
Example #5
0
    def _extend_latex_with_caption(self, latex, caption, floatable):
        if not caption:
            return latex

        caption = self.layout.get_converter().convert(caption)
        if floatable:
            return '%s\n\\caption{%s}' % (latex, caption)

        else:
            return '%s\n%s' % (
                latex,
                generate_manual_caption(caption, 'figure'))
    def get_latex(self):
        graphicname = self.register_image()

        yield r'\begin{center}'
        yield self.get_includegraphics_cmd(graphicname)

        if self.context.getShowTitle():

            yield generate_manual_caption(
                self.convert(self.context.Title()), 'figure').strip()

        yield r'\end{center}'
    def test_latex_with_small_layout(self):
        context, request, layout, converter = self.create_mocks(
            'small', 'my description', '123')

        self.replay()

        view = getMultiAdapter((context, request, layout))
        latex = view.render()

        self.assertEqual(
            latex,
            '\n'.join([
                    r'\includegraphics[width=0.25\textwidth]{123_image}',
                    generate_manual_caption('my description', 'figure')]))
Example #8
0
    def test_latex_with_middle_layout(self):
        context, request, layout, converter = self.create_mocks(
            'middle', 'the description', '3434')

        self.replay()

        view = getMultiAdapter((context, request, layout))
        latex = view.render()

        self.assertEqual(
            latex, '\n'.join([
                r'\includegraphics[width=0.5\linewidth]{3434_image}',
                generate_manual_caption('the description', 'figure'),
            ]))
Example #9
0
    def test_latex_with_small_layout(self):
        context, request, layout, converter = self.create_mocks(
            'small', 'my description', '123')

        self.replay()

        view = getMultiAdapter((context, request, layout))
        latex = view.render()

        self.assertEqual(
            latex, '\n'.join([
                r'\includegraphics[width=0.25\linewidth]{123_image}',
                generate_manual_caption('my description', 'figure')
            ]))
    def test_latex_with_middle_layout(self):
        context, request, layout, converter = self.create_mocks(
            'middle', 'the description', '3434')

        self.replay()

        view = getMultiAdapter((context, request, layout))
        latex = view.render()

        self.assertEqual(
            latex,
            '\n'.join([
                    r'\includegraphics[width=0.5\textwidth]{3434_image}',
                    generate_manual_caption('the description', 'figure'),
                    ]))
Example #11
0
    def test_small_left_nonfloating_caption(self):
        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.expect(layout.get_converter().convert('The Caption')).result(
            'THE CAPTION')
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'small', caption='The Caption')

        self.assertEqual(latex, '\n'.join((
                    r'\includegraphics[width=0.25\linewidth]{XUID_image}',
                    generate_manual_caption('THE CAPTION', 'figure'),
                    )))
Example #12
0
    def render_caption(self):
        """
        If the HTML-Table contains a <caption>-Tag, this method
        returns the LaTeX-Command for the caption and weather the
        command should be inserted at the top or at the bottom of
        the table.
        """

        caption, insert_at_top = self._get_caption_from_tag()

        if caption is None:
            caption, insert_at_top = self._get_caption_from_summary()

        if caption is None:
            return None, False

        show_in_index = 'notListed' not in self.get_css_classes()

        latex = generate_manual_caption(caption, 'table',
                                        show_in_index=show_in_index)

        return latex, insert_at_top
Example #13
0
    def test_fullwidth_does_not_float(self):
        """Using a floating area (wrapfigure) with a 100% width causes the
        following text to be floated over the image.
        Since in this case floating is not possible (the image takes 100%)
        it should switch to non-floating even when called with
        ``floatable=True``.
        """

        layout = self.mock_interface(ILaTeXLayout)
        self.expect(layout.use_package('graphicx'))
        self.expect(layout.get_builder().add_file('XUID_image.jpg', ANY))
        self.expect(layout.get_converter().convert('My Image')).result(
            'MY IMAGE')
        self.replay()

        generator = ImageLaTeXGenerator(self.context, layout)
        latex = generator(self.image, 'full', floatable=True,
                          caption='My Image')

        self.assertEqual(latex, '\n'.join((
                    r'\includegraphics[width=\linewidth]{XUID_image}',
                    generate_manual_caption('MY IMAGE', 'figure'))))
 def test_empty_caption(self):
     self.assertEqual(generate_manual_caption('', 'table'), '')
     self.assertEqual(generate_manual_caption(None, 'table'), '')
 def test_caption_with_umlaut(self):
     latex = generate_manual_caption('hall\xc3\xb6chen', 'table')
     self.assertIn(
         'Table \\thechapter.\\arabic{table}: hall\xc3\xb6chen',
         latex)