Skip to content

Refactor latex table - #3389

Merged
tk0miya merged 7 commits into
sphinx-doc:masterfrom
tk0miya:refactor_latex_table
Feb 4, 2017
Merged

tk0miya merged 7 commits into
sphinx-doc:masterfrom
tk0miya:refactor_latex_table

Conversation

@tk0miya

@tk0miya tk0miya commented Feb 4, 2017

Copy link
Copy Markdown
Member

To improve LaTeX tables, I try to refactor the LaTeX writer.

@tk0miya tk0miya added type:enhancement enhance or introduce a new feature builder:latex type:proposal a feature suggestion labels Feb 4, 2017
@tk0miya tk0miya self-assigned this Feb 4, 2017
Comment thread tests/test_build_latex.py

# longtable
table = tables['longtable']
assert ('\\begin{longtable}{|l|l|}\n\\hline' in table)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems longtable does not starts with empty line and \noindent. Is this correct?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct, longtable would not be affected by a \noindent because it behaves like a paragraph, not inline, type of object.

It admits option [l], [r], or [c] for horizontal placement, default behaviour is centering (c).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for comment!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tk0miya I am currently merging with latest update to master (#3381) and will push a branch to my fork based on yours so that you can fetch from there later to let tests pass.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but I'm refactoring the writer now. So I could not merge it.
Don't mind. I will merge master branch at the end of my work :-)

@tk0miya

tk0miya commented Feb 4, 2017

Copy link
Copy Markdown
Member Author

As a first step, I added test case for tabular macros.

Comment thread sphinx/writers/latex.py Outdated
if self.table.colspec:
self.body.append(self.table.colspec)
elif self.table.colwidths:
elif self.table.colwidths and 'colwidths-given' in self.table.classes:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfbu

jfbu commented Feb 4, 2017 •

Copy link
Copy Markdown
Contributor

@jfbu

jfbu commented Feb 4, 2017 •

Copy link
Copy Markdown
Contributor

ah actually I can make a PR on your fork I guess, will check... ok, had to fight a bit with github interface which somehow was always bringing me back to sphinx repo, but it is done at tk0miya#2

@tk0miya
tk0miya force-pushed the refactor_latex_table branch from 8489786 to 976fc32 Compare February 4, 2017 11:18
@tk0miya tk0miya changed the title [WIP] Refactor latex table Refactor latex table Feb 4, 2017
@tk0miya

tk0miya commented Feb 4, 2017 •

Copy link
Copy Markdown
Member Author

I just updated this pull request. It also includes the changes in master branch.
I used to templates for rendering tables. I believe it makes latex builder simpler.
It did not modify the rendered tex code.

I would like to continue to refactor in another pull request.
@jfbu Could you review this please?

Comment thread sphinx/writers/latex.py
elif self.is_longtable():
return '{|' + ('l|' * self.colcount) + '}\n'
else:
return '{|' + ('L|' * self.colcount) + '}\n'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about (less efficient but more robust):

        elif self.get_table_type() == 'tabulary':
            return '{|' + ('L|' * self.colcount) + '}\n'
        else:
            return '{|' + ('l|' * self.colcount) + '}\n'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! fixed.

@@ -0,0 +1,21 @@
\begin{longtable}<%= table.get_colspec() %>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is possibility in future to add [c|l|r] option here for horizontal alignment. (new :align: option of Docutils 0.13)

Comment thread sphinx/writers/latex.py Outdated
return 'longtable'
elif self.has_verbatim:
return 'tabular'
elif self.has_problematic and not self.colspec:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the table having :widths: option uses tabulary because of that but it should use tabular

in my PR I had something like

        elif self.table.has_problematic or \
             (self.table.colwidths and 'colwidths-given' in self.table.classes):

other remark is that the templates produces extra blank lines in tex output. mentioning it here because I am off now for a while, will resume later ;-) congrats on great work ! ( :align: option will cause evolutions)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG. It's my mistake...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread tests/test_build_latex.py Outdated

# table having :widths: option
table = tables['table having :widths: option']
assert ('\\noindent\\begin{tabulary}{\\linewidth}'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be assert ('\\noindent\\begin{tabular}' after remark at https://github.com/sphinx-doc/sphinx/pull/3389/files#r99466224

and \end{tabular} of course

@jfbu jfbu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@tk0miya
tk0miya merged commit b6a4b22 into sphinx-doc:master Feb 4, 2017
@tk0miya
tk0miya deleted the refactor_latex_table branch February 4, 2017 17:40
@tk0miya

tk0miya commented Feb 4, 2017

Copy link
Copy Markdown
Member Author

Merged. Thank you for reviewing!

@jfbu jfbu mentioned this pull request May 9, 2017
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

builder:latex type:enhancement enhance or introduce a new feature type:proposal a feature suggestion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants