Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretext conversion #68

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1c8dde7
Hack pavement.py as instructed.
gigamonkey Jun 9, 2023
fff3dce
Script to fix up some entities in embedded HTML
gigamonkey Jun 9, 2023
7af15f1
Improve entity fixer.
gigamonkey Jun 9, 2023
c1b69ab
More work on cleaning rst.
gigamonkey Jun 9, 2023
17a664e
Make directory for ptx
gigamonkey Jun 9, 2023
71ea40f
Seems like :endclick: needs to be on same line
gigamonkey Jun 9, 2023
7838dec
Make some fixes directly on generic XML
gigamonkey Jun 9, 2023
4b600ea
Run runestone from virtual env.
gigamonkey Jun 10, 2023
b7adccd
Make pages have only one top-level section for XML conversion.
gigamonkey Jun 10, 2023
254df08
Get rid of some inline style that is messing up XML
gigamonkey Jun 10, 2023
6b64717
Some more sections/subsection fixes.
gigamonkey Jun 10, 2023
2bd539c
Move xmlificitaion of br's into fix-xml.pl
gigamonkey Jun 10, 2023
0e641ae
Kludge to deal with top-level images breaking XML
gigamonkey Jun 10, 2023
8676988
Tidy Makefile a bit.
gigamonkey Jun 10, 2023
5f84951
Tidying Makefile
gigamonkey Jun 10, 2023
269b03f
Tidying fix-xml
gigamonkey Jun 10, 2023
551358e
Get rid of Old TOC section
gigamonkey Jun 10, 2023
9d132a7
Add build_web to Makefile
gigamonkey Jun 10, 2023
675b767
Fixup PreTeXt to include <introduction> when needed.
gigamonkey Jun 11, 2023
d23c0bf
Fix width attributes
gigamonkey Jun 11, 2023
7c686d1
Strip height attributes that PreTeXt doesn't like.
gigamonkey Jun 11, 2023
8ec41bc
Some more XML post processing.
gigamonkey Jun 11, 2023
fd0fc60
Adding another stage to XML fixups.
gigamonkey Jun 11, 2023
61b0f0f
Only put lines in when there are br's.
gigamonkey Jun 11, 2023
1c9bd62
Remove interviewees we don't have files for.
gigamonkey Jun 11, 2023
1c5b22a
Copy attributes.
gigamonkey Jun 12, 2023
e66e5c6
Add fix-ptx script for a few xrefs.
gigamonkey Jun 12, 2023
ff4d6b2
One more try to get this regex right.
gigamonkey Jun 12, 2023
4a3b92e
Generalized structure for hand fixed files.
gigamonkey Jun 13, 2023
4bf06f3
README about the conversion.
gigamonkey Jun 16, 2023
def5508
Update README_PRETEXT.md
gigamonkey Jun 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.PHONY: all fixed_source xml fixed_xml ptx post fix_ids post2 post3 build_web clean pristine

DEBUG_PRETEXT := # -v DEBUG
R2P := ~/3rdparty/Runestone2PreTeXt

xml := $(shell find build/xml -type f)
ptx := $(patsubst build/xml/%.xml,pretext/%.ptx,$(xml))

# This will run from a virtual env.
rs2ptx := python -m runestone rs2ptx

all: fixed_source fixed_xml
$(MAKE) ptx post fixed_ptx build_web

fixed_source:
find _sources/ -name '*.rst' -exec ./fix-source.pl {} \;

xml:
$(rs2ptx)

fixed_xml: xml
find build/xml -name '*.xml' -exec ./fix-xml.pl {} \;

fixed_ptx:
find pretext -name '*.ptx' -exec ./fix-ptx.pl {} \;
rsync -r hand-fixes/ pretext/

# This works better than the script that does them all
pretext/%.ptx: build/xml/%.xml | pretext
mkdir -p $(dir $@)
xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > [email protected]
xsltproc --novalid post-1.xsl [email protected] > [email protected]
xsltproc --novalid post-2.xsl [email protected] > [email protected]
cp [email protected] $@

ptx: $(ptx) pretext/rs-substitutes.xml

post:
python $(R2P)/fixIds.py
python $(R2P)/fix_xrefs.py
python $(R2P)/reformatPtx.py
cp main.ptx pretext
cp publication-rs-for-all.xml pretext
python $(R2P)/toctree2xml.py .
python $(R2P)/filltoc.py pretext _sources
python $(R2P)/copy_figs.py ./_sources ./pretext/Figures

build_web:
pretext $(DEBUG_PRETEXT) build web

pretext:
mkdir $@

pretext/rs-substitutes.xml: rs-substitutes.xml | pretext
cp $< $@

clean:
rm -rf pretext
rm -rf build/xml

pristine: clean
git restore _sources
47 changes: 47 additions & 0 deletions README_PRETEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
This branch was created mostly as an experiment to see how far I could get with
converting to PreTeXt. The basic idea was to try and automate as much as
possible so I'd be able to rerun the conversion from the latest rst source
whenever. However I didn't totally stick to that plan and made a few changes to
the .rst files. Some of them may be fixes that should be made for their own sake
but a bunch of them were just hacks to get the rst into a format where it would
convert cleanly; in particular I had to rip out several `.. raw:: html` sections
that added `<style>` elements. And I hacked `pavement.py` as instructed in the
`Runestone2PreTeXt` `README`.

Note that in conjunction with the changes in this repo I also had to make
changes in [bnmnetp/Runestone2PreTeXt][1] and [RunestoneInteractive/rs][2]. All
my changes have been submitted as PRs though they have not all been merged as of
this writing (2023-06-15). In order to run the conversion you will need to set
up a virtual env in the `rs` repo such that `python -m runestone rs2ptx` runs
`runestone` from the repo rather than the `pip` installed version.

Other than those changes, the main thing I did here was add several files:

- `Makefile`: a GNU makefile for running various parts of the conversion. You'll
need to set the `R2P` variable to the location of your local copy of the
`Runestone2PreTeXt` repo.

- `fix-source.pl`: A perl script that patches various things in the .rst files
that caused problems Some of those changes, like fixing unescaped & and < in
embedded HTML should perhaps be committed to the source.

- `fix-xml.pl`: A perl script to fix the first batch of XML generated with
sphinx, to make it actually valid XML. Some of the bits in here, as one of
the comments mentions, may no-longer be necessary as some of my fixes to the
Runestone scripts may now cover them.

- `fix-ptx.pl`: A perl script that patches up a few xrefs in the generated ptx.

- `post-1.xsl` and `post-2.xsl`: two XSLT stylesheets that are run by the
`Makefile` after the main XSLT stylesheet from `Runestone2PreTeXt`.

- `hand-fixes/Unit8-2DArray/routeCipherA.ptx`: This is one file that I just gave
up and hand fix the generated ptx. The makefile will copy this file over the
generated one so if the .rst source changes, the hand fixes will need to be
redone. But the mechanism is general so any .ptx file that doesn't come out
quite right can be replaced with a parallel file under the `hand-fixes`
directory.


[1]: <https://github.com/bnmnetp/Runestone2PreTeXt/pulls?q=is%3Apr+author%3Agigamonkey>
[2]: <https://github.com/RunestoneInteractive/rs/pulls?q=+is%3Apr+author%3Agigamonkey>
12 changes: 2 additions & 10 deletions _sources/Stories/intervieweeIndex.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. image:: ../../_static/CSAwesomeLogo.png
.. |LogoImageToBeFixed| image:: ../../_static/CSAwesomeLogo.png
:width: 350
:align: center

Expand All @@ -18,16 +18,8 @@ Meet The Interviewees
Interviewees/E_Espinoza.rst
Interviewees/G_Opoku-Boateng.rst
Interviewees/J_Gilbert.rst
Interviewees/L_Diaz.rst
Interviewees/L_Morales.rst
Interviewees/L_Vocos.rst
Interviewees/L_Diaz.rst
Interviewees/M_Rodriguez.rst
Interviewees/N_Gaskins.rst
Interviewees/O_Romero.rst
Interviewees/R_Garcia.rst
Interviewees/R_Tillman-French.rst
Interviewees/S_Seibel.rst
Interviewees/S_Vivas.rst
Interviewees/T_Pope.rst
Interviewees/W_Sheppard.rst
Interviewees/Y_Salazar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
:align: middle
:alt: groupwork

.. raw:: html

<style> td { text-align: left; } </style>


.. index::
single: operators
pair: math; operators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Once strMethod("y") returns, the value from each recursive call on the stack can


Summary
============
-------

- A recursive method is a method that calls itself.

Expand Down
8 changes: 4 additions & 4 deletions _sources/Unit10-Recursion/topic-10-1-recursion-day1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ This method will print out "This is the method that never ends!" and then call i


Why use Recursion?
==================
------------------

.. index::
single: fractal
Expand All @@ -126,7 +126,7 @@ Recursion can also be used to create fractals. A simple example is Sierpinski's
Recursion can also be used to traverse String, array, and ArrayList objects, much like a loop. In fact, any recursive solution could be written with iteration (loops) instead.

Factorial Method
=================
----------------


The following video is also on YouTube at https://youtu.be/V2S_8E_ubBY. It introduces the concept of recursion and tracing recursion with the factorial method.
Expand Down Expand Up @@ -209,7 +209,7 @@ See the method `factorial` below that calculates the **factorial** of a number.


Base Case
==========
---------

.. index::
single: base case
Expand Down Expand Up @@ -307,4 +307,4 @@ Every recursive method must have at least one **base case** which halts the recu
}


Continue to the next page for Day 2 of the Recursion lesson.
Continue to the next page for Day 2 of the Recursion lesson.
9 changes: 0 additions & 9 deletions _sources/Unit2-Using-Objects/toctree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,3 @@ AP CS A Exam Weighting: 5-7.5%
Exercises.rst
JavaSwingGUIs.rst

.. Old TOC
whatIsJava.rst
introClassObject.rst
firstClass.rst
compileTimeErrors.rst
firstOOClass.rst
runClass.rst
partsOfAClass.rst
JavaBasicsSummary.rst
4 changes: 0 additions & 4 deletions _sources/Unit3-If-Statements/topic-3-5-compound-ifs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
:align: middle
:alt: groupwork

.. raw:: html

<style> td { text-align: left; } </style>

.. image:: ../../_static/time90.png
:width: 225
:align: right
Expand Down
6 changes: 1 addition & 5 deletions _sources/Unit3-If-Statements/topic-3-6-DeMorgan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
:align: middle
:alt: groupwork

.. raw:: html

<style> td { text-align: left; } </style>

.. image:: ../../_static/time90.png
:width: 225
:align: right
Expand Down Expand Up @@ -393,4 +389,4 @@ Summary

- Truth tables can be used to prove that 2 Boolean expressions are identical.

- Equivalent Boolean expressions will evaluate to the same value in all cases.
- Equivalent Boolean expressions will evaluate to the same value in all cases.
8 changes: 4 additions & 4 deletions _sources/Unit7-ArrayList/2019delimitersQ3a.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ There are problems in this section that can help you check your understanding of
:optional:

:click-incorrect:A string:endclick::click-incorrect: containing text and possibly delimiters has been split into *tokens* and stored inTest2:endclick:
:click-correct:String[] tokens:endclick:. :click-incorrect:Each token is either an open delimiter, a close delimiter, or a substring that is not a
delimiter:endclick:. :click-incorrect: You will write the method :endclick::click-incorrect:getDelimitersList:endclick:, :click-incorrect: which returns an:endclick: :click-correct:ArrayList:endclick::click-incorrect:
containing all the open and close delimiters found in tokens in their original order.:endclick:
:click-correct:String[] tokens:endclick:. :click-incorrect:Each token is either an open delimiter, a close delimiter, or a substring that is not a delimiter:endclick:.
:click-incorrect: You will write the method :endclick::click-incorrect:getDelimitersList:endclick:, :click-incorrect: which returns an:endclick: :click-correct:ArrayList:endclick:
:click-incorrect:containing all the open and close delimiters found in tokens in their original order.:endclick:


.. reveal:: delim_cu_r2
Expand Down Expand Up @@ -241,7 +241,7 @@ containing all the open and close delimiters found in ``tokens`` in their origin

.. activecode:: frq2019Q3A-delim
:language: java
:autograde: unittest
:autograde: unittest

Write the method getDelimitersList in the code below. The main method contains code to test your solution.
~~~~
Expand Down
4 changes: 0 additions & 4 deletions _sources/Unit7-ArrayList/topic-7-2-arraylist-methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
:width: 250
:align: right

.. raw:: html

<style> td { text-align: left; } </style>

ArrayList Methods
=========================

Expand Down
4 changes: 0 additions & 4 deletions _sources/Unit7-ArrayList/topic-7-5-searching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
:align: middle
:alt: groupwork

.. raw:: html

<style> td { text-align: left; } </style>

.. image:: ../../_static/time90.png
:width: 225
:align: right
Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit8-2DArray/a2dHardMC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:start: 7

Hard Multiple Choice Questions
----------------------------------
==============================

These problems are harder than those that you will typically see on the AP CS A exam.

Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit8-2DArray/topic-8-1-2D-arrays-Day1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
:align: right

2D Arrays (Day 1)
-----------------
=================

.. index::
single: 2D Arrays
Expand Down
4 changes: 2 additions & 2 deletions _sources/Unit8-2DArray/topic-8-1-2D-arrays-Day2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
:align: right

Set Value(s) in a 2D Array (Day 2)
----------------------------------------
==================================

.. index::
pair: 2D Array; initialization
Expand Down Expand Up @@ -444,4 +444,4 @@ Try the game below to practice 2D Arrays. Click on **Arrays** and then check on

.. raw:: html

<iframe height="700px" width="100%" style="margin-left:10%;max-width:80%" src="https://csa-games.netlify.app/"></iframe>
<iframe height="700px" width="100%" style="margin-left:10%;max-width:80%" src="https://csa-games.netlify.app/"></iframe>
2 changes: 1 addition & 1 deletion _sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
:align: right

Nested Loops for 2D Arrays (Day 1)
-----------------------------------
==================================

In this lesson, you will learn how to use nested loops to traverse a 2D Array.

Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
:align: right

Enhanced For-Each Loop for 2D Arrays (Day 2)
----------------------------------------------------
============================================

.. index::
pair: 2D Array; for-each loop
Expand Down
4 changes: 2 additions & 2 deletions _sources/Unit9-Inheritance/topic-9-1-inheritance-day1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
:align: right

Inheritance (Day 1)
-------------------
===================

One of the really useful features of Object-Oriented programming is **inheritance**. You may have heard of someone coming into an inheritance, which often means they were left something from a relative who died. Or, you might hear someone say that they have inherited musical ability from a parent. In Java all classes can **inherit** attributes (instance variables) and behaviors (methods) from another class. The class being inherited from is called the **parent class** or **superclass**. The class that is inheriting is called the **child class** or **subclass**.

Expand Down Expand Up @@ -181,4 +181,4 @@ The Student class can also inherit from the class Person just like Employee and
boolean passed = checkCodeContains("Student extends Person");
assertTrue(passed);
}
}
}
2 changes: 1 addition & 1 deletion _sources/Unit9-Inheritance/topic-9-1-inheritance-day2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
:align: right

is-a vs. has-a (Day 2)
---------------------------------------
======================

.. index::
single: has-a
Expand Down
21 changes: 21 additions & 0 deletions fix-ptx.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env perl

#
# Ad-hoc fixes to the generated ptx that aren't worth trying to handle properly
# in the conversion and XML rewriting.
#

use warnings;
use strict;

$^I = '';

while (<>) {

# Translate xml:ids that were generated in the docs to the ones used in the xrefs.
s/xml:id="_briceida-mariscal-id1(-\d+)?"/xml:id="interviewees_b_-mariscal"/g;
s/xml:id="_carla-de-lira-id1(-\d+)?"/xml:id="interviewees_c_-de_-lira"/g;
s/xml:id="_camille-mbayo-id1(-\d+)?"/xml:id="interviewees_c_-mbayo"/g;

print;
}
Loading