Skip to content

Conversion of Tutorial from LaTeX to RST for Sphinx - #4371

Merged
peterjc merged 21 commits into
biopython:masterfrom
peterjc:sphinx
Jan 4, 2024
Merged

peterjc merged 21 commits into
biopython:masterfrom
peterjc:sphinx

Conversation

@peterjc

@peterjc peterjc commented Jul 21, 2023 •

Copy link
Copy Markdown
Member
  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run pre-commit
    locally, and understand that continuous integration checks will be used to
    confirm the Biopython unit tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

Would close #907 but this PR is not ready yet.

My plan is to work on this PR with occasional rebasing on the master to get the latest changes to the LaTeX files (which will require rerunning the pandoc conversion with a suitable version of pandoc, and fixing any conflicts which follow - especially in figure captions).

Automatic deployment ought to work as a simple extension of the current API doc deployment to https://github.com/biopython/docs

Final commits would remove the helper scripts and the LaTeX files.

@peterjc

peterjc commented Jul 21, 2023

Copy link
Copy Markdown
Member Author

Local testing is using:

$ sphinx-build --version
sphinx-build 6.2.1

and

$ pandoc --version
pandoc 2.19.2
Compiled with pandoc-types 1.22.2.1, texmath 0.12.5.2, skylighting 0.13,
citeproc 0.8.0.1, ipynb 0.2, hslua 2.2.1
Scripting engine: Lua 5.4
User data directory: /home/pcock/.local/share/pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

(The old version of pandoc is to avoid a regression in LaTeX to RST conversion of figure metadata, that should be fixed in their next release)

Currently output:

$ make html
Running Sphinx v6.2.1
making output directory... done
<snip>
reading sources... [100%] index
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_align.rst:542: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:13: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:51: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:51: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:276: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:1076: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:1076: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:1193: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:1224: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cluster.rst:1704: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_cookbook.rst:673: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_graphics.rst:23: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_graphics.rst:32: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_graphics.rst:32: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_graphics.rst:565: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_graphics.rst:736: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_graphics.rst:991: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_introduction.rst:119: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_introduction.rst:126: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_introduction.rst:129: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_introduction.rst:132: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_introduction.rst:135: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_introduction.rst:138: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_introduction.rst:141: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_motifs.rst:183: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_motifs.rst:183: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_motifs.rst:239: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_motifs.rst:795: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_motifs.rst:952: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:6: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:97: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:179: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:220: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:915: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:1535: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:1617: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:1617: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:1653: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pdb.rst:1677: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pdb.rst:1711: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pdb.rst:1827: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pdb.rst:2075: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pdb.rst:2075: ERROR: Unknown interpreted text role "raw-latex".
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_phylo.rst:11: ERROR: Unknown interpreted text role "raw-latex".
WARNING: autodoc: failed to import module 'Alphabet'; the following exception was raised:
No module named 'Alphabet'
looking for now-outdated files... none found
pickling environment... done
checking consistency... /home/pcock/repositories/biopython/Doc/api/Alphabet.rst: WARNING: document isn't included in any toctree
/home/pcock/repositories/biopython/Doc/biopdb_faq.rst: WARNING: document isn't included in any toctree
done
preparing documents... done
writing output... [100%] index
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_motifs.rst:1051: WARNING: Failed to create a cross reference. A title or caption not found: 'table:transfaccodes'
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pairwise.rst:328: WARNING: Failed to create a cross reference. A title or caption not found: 'table:align-meta-attributes'
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pdb.rst:1611: WARNING: Failed to create a cross reference. A title or caption not found: 'table:ic-attribs'
/home/pcock/repositories/biopython/Doc/Tutorial/chapter_pdb.rst:1744: WARNING: Failed to create a cross reference. A title or caption not found: 'table:dssp-codes'
/home/pcock/repositories/biopython/Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain
/home/pcock/repositories/biopython/Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain.__init__:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain
generating indices... genindex py-modindex done
writing additional pages... search done
copying images... [100%] images/phylo-draw-example.png
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build finished with problems, 53 warnings.
make: *** [Makefile:20: html] Error 1

The ERROR: Unknown interpreted text role "raw-latex". bits are from the bibliography citations.

The table cross-references have not been addressed yet:

Doc/Tutorial/chapter_motifs.rst:1051: WARNING: Failed to create a cross reference. A title or caption not found: 'table:transfaccodes'
Doc/Tutorial/chapter_pairwise.rst:328: WARNING: Failed to create a cross reference. A title or caption not found: 'table:align-meta-attributes'
Doc/Tutorial/chapter_pdb.rst:1611: WARNING: Failed to create a cross reference. A title or caption not found: 'table:ic-attribs'
Doc/Tutorial/chapter_pdb.rst:1744: WARNING: Failed to create a cross reference. A title or caption not found: 'table:dssp-codes'

This looks like a false positive as the two class references are explicitly using Bio.PDB.Chain.Chain for disambiguation. Could be a sphinx regression, but worth checking master branch API build logs.

/home/pcock/repositories/biopython/Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain
/home/pcock/repositories/biopython/Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain.__init__:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain

@peterjc

peterjc commented Jul 21, 2023

Copy link
Copy Markdown
Member Author

This would resolve #4228 by dropping the arguments to the minted blocks before converting them to RST.

@peterjc

peterjc commented Jul 22, 2023

Copy link
Copy Markdown
Member Author

I'm thinking of using the basic RST citation function for our references:
https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#citations

This would mean transforming the embedded reference list from here https://github.com/biopython/biopython/blob/biopython-181/Doc/Tutorial.tex

\begin{thebibliography}{99}
\bibitem{cock2009}
Peter J. A. Cock, Tiago Antao, Jeffrey T. Chang, Brad A. Chapman, Cymon J. Cox, Andrew Dalke, Iddo Friedberg, Thomas Hamelryck, Frank Kauff, Bartek Wilczynski, Michiel J. L. de Hoon: ``Biopython: freely available Python tools for computational molecular biology and bioinformatics''. {\it Bioinformatics} {\bf 25} (11), 1422--1423 (2009).
\url{https://doi.org/10.1093/bioinformatics/btp163}
...
\end{thebibliography}

into something like this:

.. [cock2009] Peter J. A. Cock, Tiago Antao, Jeffrey T. Chang, Brad A. Chapman, Cymon J. Cox, Andrew Dalke, Iddo Friedberg, Thomas Hamelryck, Frank Kauff, Bartek Wilczynski, Michiel J. L. de Hoon: ``Biopython: freely available Python tools for computational molecular biology and bioinformatics''. *Bioinformatics* **25** (11), 1422--1423 (2009).
https://doi.org/10.1093/bioinformatics/btp163

Happily for this plan, we're not using the bibtex format.

@peterjc

peterjc commented Jul 23, 2023

Copy link
Copy Markdown
Member Author

Confirming that using Sphinx 4.3.2 (as currently used by GitHub Actions for the API docs) avoids this error which does look then like a regression somewhere in Sphinx:

Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain
Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain.__init__:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain

Instead we get a different error "duplicated entry found in toctree" in the autogenerated API docs...

The "more than one target" also appears in Sphinx 4.4.0, 4.5.0, 5.0.2, 5.1.1, 5.2.3, 5.3.0 and 6.2.1 (I should have started testing the older releases in hindsight).

It would probably be prudent to pin versions once I have this all working!

@peterjc

peterjc commented Jul 23, 2023 •

Copy link
Copy Markdown
Member Author

As to references, using this in RST

Please cite our application note [cock2009]_ as the ...

Renders like this:

Please cite our application note [cock2009] as the ...

where the square brackets shows the citation key as-s, and as a clickable link to the bibliography. For that the raw RST can be:

.. [cock2009] P.J.A. Cock *et al.* (2009) Biopython: freely available Python tools for computational molecular biology and bioinformatics. *Bioinformatics* **25** (11), 1422--1423 https://doi.org/10.1093/bioinformatics/btp163

And that rendered fine - but again shows the raw citation key as-is. My inclination is to change the keys to title case first author and year.

So not as much control as LaTeX offers, but good enough (and we can change this later if we really want to).

@peterjc

peterjc commented Jul 23, 2023

Copy link
Copy Markdown
Member Author

The bibliograph using the basic RST citations could be prettier - the varied key lengths don't help:

Screenshot 2023-07-23 at 13 30 00

A few of the entries wrap strangely:

Screenshot 2023-07-23 at 13 31 59

Possibly related to the stray slashes still there from LaTeX accented characters...

@peterjc

peterjc commented Jan 1, 2024

Copy link
Copy Markdown
Member Author

Rebase without re-running pandoc (simpler), note will want to remove recent additions of \hypertarget to chapter_pairwise.tex before refreshing the actual conversion again.

@peterjc
peterjc force-pushed the sphinx branch 4 times, most recently from 48b53ef to 904bfde Compare January 1, 2024 22:28
@peterjc

peterjc commented Jan 1, 2024

Copy link
Copy Markdown
Member Author

Will have to decide if want to use :math:`k`-means as it stands, or simplify to *k*-means using italics which will work more generally.

Likewise for :math:`\beta` or. :math:`n \times m` we might want to try a unicode beta or multiplication symbols.

However, that's not something I want to worry about right now. See https://docutils.sourceforge.io/docs/ref/rst/roles.html#math

@peterjc

peterjc commented Jan 1, 2024

Copy link
Copy Markdown
Member Author

The HTML build looks to be working without errors on CircleCI using Sphinx v4.3.2

Locally on macOS using Sphinx 7.2.6 however, there are two warnings (which are treated as an error in strict mode):

...
writing output... [100%] index
/Users/pc40583/repositories/biopython/Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain
/Users/pc40583/repositories/biopython/Bio/PDB/internal_coords.py:docstring of Bio.PDB.internal_coords.IC_Chain.__init__:1: WARNING: more than one target found for cross-reference 'Chain': Bio.Nexus.Nodes.Chain, Bio.PDB.Chain.Chain
generating indices... genindex py-modindex done
writing additional pages... search done
dumping search index in English (code: en)... done
dumping object inventory... done
build finished with problems, 2 warnings.
make: *** [html] Error 1

See notes above about this. It looks like a false positive as two fragments do not reference the class as just "Chain" but deliberately use the fully qualified name.

@peterjc

peterjc commented Jan 1, 2024

Copy link
Copy Markdown
Member Author

Question: Should the git history remove *.tex and add *.rst, or should it be recorded as a rename then conversion?

@peterjc

peterjc commented Jan 3, 2024

Copy link
Copy Markdown
Member Author

@mdehoon I'll have to refresh this again since the LaTeX files are in flux, but can you comment on the general approach here for conversion to RST and building the Tutorial in Sphinx alongside the API docs? Thanks!

@mdehoon

mdehoon commented Jan 3, 2024

Copy link
Copy Markdown
Contributor

@peterjc I don't have a strong opinion about it.

@peterjc

peterjc commented Jan 3, 2024

Copy link
Copy Markdown
Member Author

Do you have a lot more Tutorial changes pending? If not, perhaps I should refresh the conversion and apply the changes this week.

@mdehoon

mdehoon commented Jan 3, 2024

Copy link
Copy Markdown
Contributor

@peterjc I can hold off on tutorial changes until this PR is done.

@peterjc

peterjc commented Jan 3, 2024

Copy link
Copy Markdown
Member Author

I've pulled out some of the base changes as #4565 which I plan to merge shortly.

This now also includes the updates for test_Tutorial.py (working locally).

peterjc and others added 16 commits January 3, 2024 21:20
Note doc8 is not happy yet!

Sphinx/RST needs relative image paths - while for LaTeX we
used include-file, so was relative to parent dir.

Replacing Figure<nbsp>:ref: with :numref:

Note sed-trickery to preserve our doctest comment lines.

NOTE - Using pandoc v2.19.2 to ensure sensible figure output

$ for f in *.tex; do echo "Converting $f to rst";  sed "s/^%doctest/\n\\\\pandocignoreme .. doctest/g" $f | sed "s/^%cont-doctest/\n\\\\pandocignoreme .. cont-doctest/g" | pandoc --strip-comments  -f latex -t rst  | ../../.github/ref_fix.py - | sed "s#.. figure:: images/#.. figure:: ../images/#g" | sed "s# image:: images/# image:: ../images/#g" | sed "s/Figure :ref:/:numref:/g" > ${f%.*}.rst; done
Also avoid using math mode in the label
Also solves 'WARNING: document isn't included in any toctree' from Sphinx
Avoiding hard breaks in longer attribute names
and empty entries from some rows
Setup header, then:

$ python ../.github/rst_bibitem.py Tutorial.tex >> Tutorial/chapter_bibliography.rst
D000 Unknown target name: seems to give false positives
on citations, probably as they are in a separate file.

D001 Line too long: we ought to review this later, we
might be able to improve on the pandoc layout.

D002 Trailing whitespace: probably from doctests, which
is hard to avoid.
Original commit from Anil Tuncel, 27 July 2019,
on pull request biopython#2188.

Cherry-picked, conflicts fixed, path assumptions
updated, documentation and error messages updated,
by Peter Cock.
@peterjc peterjc changed the title Draft/WIP conversion of Tutorial from LaTeX to RST for Sphinx Conversion of Tutorial from LaTeX to RST for Sphinx Jan 3, 2024
@peterjc
peterjc merged commit 1419491 into biopython:master Jan 4, 2024
@peterjc
peterjc deleted the sphinx branch January 4, 2024 09:10
@peterjc

peterjc commented Jan 4, 2024 •

Copy link
Copy Markdown
Member Author

The Sphinx generated HTML Tutorial is now live on https://biopython.org/docs/dev/ alongside https://biopython.org/docs/dev/api/ following the big automated update which worked as expected via the CI, biopython/docs@dc91097

peterjc added a commit that referenced this pull request Jan 4, 2024
Should have been included in #4371.
@peterjc peterjc mentioned this pull request Jan 4, 2024
3 tasks done
peterjc added a commit that referenced this pull request Jan 5, 2024
Should have been included in #4371.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replacing LaTeX based Tutorial (pdflatex and hevea)?

3 participants