Skip to content

Replacing LaTeX based Tutorial (pdflatex and hevea)? #907

Closed

Description

@peterjc

This replaces old issue https://redmine.open-bio.org/issues/3221 Port the Biopython Tutorial to Sphinx/reStructuredText (filed by @etal), and part of overlapping issue https://redmine.open-bio.org/issues/3219 Port Biopython documentation to Sphinx (also filed by @etal).

We can likely use pandoc as a first pass of converting the current LaTeX source for the tutorial into a more modern markdown language like reStructuredText (*.rst, currently used in our docstrings) or MarkDown (*.md, currently used for our website).

Any conversion will also need to rewrite test_Tutorial.py which pulls doctest formatted examples out of the tutorial source (together with a simple dependency mechanism).

Activity

  1. peterjc commented on Aug 3, 2016

    @peterjc
    MemberAuthor

    See also #906 about replacing epydoc for generating our API documentation from the docstrings, which are currently written using reStructuredText

  2. peterjc commented on Aug 3, 2016

    @peterjc
    MemberAuthor

    Currently we have three markup languages in use:

    • Markdown for the website (converted from MediaWiki), plus GitHub issues
    • reStructuredText for the API documentation from docstrings (Replacing epydoc for API documentation #906)
    • LaTeX for the Tutorial and Cookbook (this issue)

    Is switching to markdown viable for a document at complex as the current Tutorial? If we switched the docstrings as well (see pdoc suggestion on #906) this would be much more attractive as a single option.

  3. peterjc commented on Aug 3, 2016

    @peterjc
    MemberAuthor

    A relevant comment from @etal on https://redmine.open-bio.org/issues/3221

    While we're at it, we may want to slim down the Tutorial and move some of the more detailed material to a separate Reference based on the automated API docs.

    Having both the docstrings and the Tutorial written in the same markup language would make this sort of restructuring much easier in future (regardless of if we use reStructuredText or MarkDown, which seem to be the only sensible choices).

  4. peterjc commented on Aug 3, 2016

    @peterjc
    MemberAuthor

    In order to preserve the test_Tutorial.py functionality (which I feel has been well worth the time investment so far in both keeping the examples working, but also sometimes catching bugs not covered by the main test suite), we will likely need to define a special comment or markup block.

    For markdown https://stackoverflow.com/questions/4823468/comments-in-markdown suggests something like this for a comment:

    (empty line)
    [comment]: # (This actually is the most platform independent comment)
    

    Alternatively we might use Markdown's fenced code blocks feature (triple back-ticks) with a bespoke info-string (rather than just python for the colour syntax markup)?

  5. MarkusPiotrowski commented on Aug 3, 2016

    @MarkusPiotrowski
    Contributor

    I find this https://gist.github.com/dupuy/1855764 document interesting, which shows how to write text that can usually be understood by both reStructuredText and Markdown interpreters. When we try to follow these guidelines for the homepage and the docstrings, a later swith to one of the two markup languages may be easier.

  6. MarkusPiotrowski commented on Aug 3, 2016

    @MarkusPiotrowski
    Contributor

    With respect to 'slimming down the tutorial' I disagree. I would prefer to have even more examples and details in the tutorial, so that I don't have to switch back and forth between the tutorial, the cookbook sections of the homepage, the wiki entries of the homepage and the api documentation (and the source code for the undocumented functions). So why don't we call the tutorial 'manual' and build it as the main comprehensive Biopython documentation source?

  7. peterjc commented on Aug 3, 2016

    @peterjc
    MemberAuthor

    Text which is simultaneously both Markdown and reStructuredText is an intriguing idea, but practically we'd loose out on Python syntax formatted examples etc.

    But let's keep this issue on the technical side about what (if anything) we should use instead of LaTeX?

  8. bosborne commented on Mar 12, 2017

    @bosborne
    Contributor

    I think that reST would be preferable given its compatibility with Sphinx and Python documentation generally, but on the other hand it looks like there's still no syntax highlighting of Python code blocks in reST files in GitHub. That argues for Markdown. Any new thoughts on this? Happy to help, if an approach is chosen.

  9. peterjc commented on Mar 12, 2017

    @peterjc
    MemberAuthor

    I'm leaning very much towards RST - we're already using it for the Python docstrings in the code itself, and the misc text files.

  10. peterjc commented on Jul 18, 2019

    @peterjc
    MemberAuthor

    Following the work in #2172 etc to close #906, we now have the API documentation (docstring comments written in RST) converted to HTML documentation using Sphinx.

    I have now managed a proof of principle conversion of the Tutorial from LaTeX into RST, and combined this with the API documentation using Sphinx (which could be deployed on our website via GitHub pages, and/or on Read The Docs).

    I deliberately kept one page per chapter (i.e. one *.rst file per chapter, like we have now one *.tex file per chapter). That has a side effect of complicating links between pages from the LaTeX \label{XXX} and \ref{XXX}, but I can fix that by converting them to RST style :ref: entries (and we give up on having chapter and section numbering in the link captions).

    I'm unsure at this point if any automated conversion is realistic as part of the continuous integration system. It would be more realistic to aim for a one-off conversion from LaTeX to RST. Thereafter contributors would only need to learn RST for writing or editing the main Biopython documentation.

  11. peterjc commented on Aug 12, 2019

    @peterjc
    MemberAuthor

    During the BOSC CoFest 2019, @anilbey was able to convert test_Tutorial.py to work with RST files - pull request #2188.

    Another idea is to use sphinx's built in doctest support - but as far as I know that lacks any fine grained control (e.g. dependencies). We would also have to update all the examples to use a particular working directory for relative paths.

  12. peterjc commented on Jul 7, 2021

    @peterjc
    MemberAuthor

    As noted on #3658, it looks like my earlier experiments had left https://biopython.readthedocs.io/ live with a version from July 2019.

    I think if we do the LaTeX to RST conversion now, we'd put the Sphinx build on our GitHub pages site instead - alongside the Sphinx RST API documentation.

    Update: I deleted the RTD pages. We might also consider dual hosting in future?

  13. JoaoRodrigues commented on Feb 13, 2023

    @JoaoRodrigues
    Member

    Hey Peter,

    Yesterday going through the process of building the release it was a bit frustrating to handle all these doc-building quirks. Is this move to rst still desirable? I'd be willing to spend some time doing the one-off conversion and cleaning, hopefully making everything a little simpler to build in the future?

  14. peterjc commented on Feb 17, 2023

    @peterjc
    MemberAuthor

    Yes, that was the goal with moving off LaTeX to RST - which seemed last time I looked at this to be the only viable alternative (and we're using it for our docstrings and API docs via Sphinx). It ought to be possible to automatically deploy this just like we autodeploy the API docs.

    See https://github.com/biopython/biopython/tree/sphinx (would need to try rebasing this, where the pandoc steps would be re-run rather than manual conflict resolution), which as I recall was on the main repository in order to render on ReadTheDocs. I had a copy at https://github.com/peterjc/biopython/tree/sphinx too.

  15. peterjc commented on Jun 21, 2023

    @peterjc
    MemberAuthor

    I've been working on this again at https://github.com/peterjc/biopython/tree/sphinx_2023 based on my previous efforts. I have the hevea-specific LaTeX cleaned up (scripted), and sensible looking output from Sphinx. As discussed above this uses one RST file per chapter, and converts the section references into :ref: commands so that they work between chapters.

    There are some glitches with figures, RST/Sphinx seems to want one-line caption titles before any extended caption text. That's OK to resolve manually.

    Currently the citations and bibliography are a stubling block. We have about 45 entries, about half with a DOI. If they all had a DOI or URL, I'd be happy with replacing them with links (e.g. link text like Cock et al. (2009) with the DOI as the URL). However, that does not cover everything.

    The built-in citation support in RST/Sphinx is basic, e.g. https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#citations - but should probably work. I need to convert a couple by hand to confirm that.

    We might instead consider https://pypi.org/project/sphinxcontrib-bibtex/ which would mean turning the bibliography from a list of \bibtex entries of pre-formatted text into a traditional bibtex file of fields. This is not the nicest file format to work with, but most bibliography packages can export this.

  16. peterjc commented on Jun 22, 2023

    @peterjc
    MemberAuthor

    Looks like table references will also need checking, proably similar to figures.

    Equation references look more tricky (not numbered by default), but we only have two labelled equations - both in the machine learning chapter. Perhaps with minor editing we can avoid explicit references to them?

  17. mdehoon commented on Jun 22, 2023

    @mdehoon
    Contributor

    @peterjc Maybe it's time to deprecate the machine learning code in Biopython? Things like logistic regression are better served in a machine learning library like scikit-learn than in Biopython.

  18. peterjc commented on Jun 22, 2023

    @peterjc
    MemberAuthor

    That may be wise (deprecating the logistic regression code), likewise the generic plotting stuff in Bio.Graphics. I'll keep that in mind as deleting the chapter might be easier than converting it ;)

  19. peterjc commented on Jul 12, 2023

    @peterjc
    MemberAuthor

    My figure caption issue seems in part to be an issue in recent versions of pandoc, jgm/pandoc#8930 - with that avoided, :numref: works nicely with the Figures (after editing the handful with multi-line captions).

    And also there are some table references which I need to look at...

    Doc/Tutorial/chapter_align.rst:1974: WARNING: Failed to create a cross reference. A title or caption not found: 'table:align-meta-attributes'
    Doc/Tutorial/chapter_motifs.rst:946: WARNING: Failed to create a cross reference. A title or caption not found: 'table:transfaccodes'
    Doc/Tutorial/chapter_pdb.rst:1594: WARNING: Failed to create a cross reference. A title or caption not found: 'table:ic-attribs'
    Doc/Tutorial/chapter_pdb.rst:1727: WARNING: Failed to create a cross reference. A title or caption not found: 'table:dssp-codes'
    
  20. peterjc commented on Jan 3, 2024

    @peterjc
    MemberAuthor

    Adding a note here from the test_Tutorial.py work on #2188, we need to convert our special LaTeX comment lines used to flag and customize doctests within the LaTeX source. For example:

    %doctest ../Tests/GenBank
    \begin{minted}{pycon}
    >>> from Bio import SeqIO
    >>> original_rec = SeqIO.read("NC_005816.gb", "genbank")
    \end{minted}
    
    Text here
    
    %cont-doctest
    \begin{minted}{pycon}
    >>> import random
    >>> nuc_list = list(original_rec.seq)
    >>> random.shuffle(nuc_list)  # acts in situ!
    \end{minted}
    

    Using RST comments:

    .. doctest ../Tests/GenBank
    
    .. code:: pycon
    
        >>> from Bio import SeqIO
        >>> original_rec = SeqIO.read("NC_005816.gb", "genbank")
    
    Text here
    
    .. cont-doctest
    
    .. code:: pycon
    
        >>> import random
        >>> nuc_list = list(original_rec.seq)
        >>> random.shuffle(nuc_list)  # acts in situ!
    

    Sadly pandoc does not handle comments jgm/pandoc#1926

    The workaround was a search-and-replace before calling pandoc, using \pandocignoreme .. doctest ../Tests/GenBank and \pandocignoreme .. cont-doctest for this example. Pandoc seems to ignore the undefined latex term, and just leaves the following text as a line in the output. We can do this with sed, e.g. sed "s/^%doctest/\n\\\\pandocignoreme .. doctest/g" (adding an extra blank line in case there wasn't one to ensure this is not tacked onto the previous paragraph).

  21. peterjc commented on Sep 19, 2024

    @peterjc
    MemberAuthor

    Note if we were to adopt pytest, then https://github.com/scientific-python/pytest-doctestplus might cover most of our doctests in RST files needs (currently handled via test_Tutorial.py). See scientific-python/pytest-doctestplus#264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions