Section C.3 Problem Solving
Subsection C.3.1 MBX
MBX is the old name for the utility script. Now called pretext/pretext.
I had some trouble getting the mbx
program working, with the message
File "/Users/whaynes/ptx/mathbook/script/mbx", line 771, in youtube_thumbnail import requests ImportError: No module named requests
I tried installing the requests module with
==> sudo pip install requests
But it didn't work :(
The problem was that when I tried to import the requests module with pip, it got installed into the wrong version of python. I had to do this to straighten it out. I'm using macPorts.
==> port select --list python Available versions for python: none python27 (active) python27-apple python37 ==> port select --list pip Available versions for pip: none pip27 pip37 (active) ==> sudo port select --set pip pip27 Selecting 'pip27' for 'pip' succeeded. 'pip27' is now active. ==> sudo pip install requests
Also, to get the mbx
program to work, I had to install pageres-cli which required installation of nodejs. On mac, this resulted in an installation error due to file permissions, and was resolved by installing pagres-cli this way sudo
> npm install --global pageres-cli --unsafe-perm=true
PDF Crop Margins 7/12/20
pdfcrop was deprecated here.
- pip install pdfCropMargins
- add python to path in .zshrc as noted by installation notes
- kernel panic ???
whaynes:statics/ (master✗) $ pip install pdfCropMargins [11:55:10] Defaulting to user installation because normal site-packages is not writeable Collecting pdfCropMargins Downloading pdfCropMargins-0.2.8.tar.gz (1.8 MB) |████████████████████████████████| 1.8 MB 2.4 MB/s Collecting wheel Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB) Collecting pillow>=6.2.2 Downloading Pillow-7.2.0-cp37-cp37m-macosx_10_10_x86_64.whl (2.2 MB) |████████████████████████████████| 2.2 MB 15.3 MB/s Collecting PyPDF2 Downloading PyPDF2-1.26.0.tar.gz (77 kB) |████████████████████████████████| 77 kB 5.0 MB/s Using legacy setup.py install for pdfCropMargins, since package 'wheel' is not installed. Using legacy setup.py install for PyPDF2, since package 'wheel' is not installed. Installing collected packages: wheel, pillow, PyPDF2, pdfCropMargins WARNING: The script wheel is installed in '/Users/whaynes/Library/Python/3.7/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Running setup.py install for PyPDF2 ... done Running setup.py install for pdfCropMargins ... done Successfully installed PyPDF2-1.26.0 pdfCropMargins-0.2.8 pillow-7.2.0 wheel-0.34.2 whaynes:statics/ (master✗) $ [11:59:27]
Subsection C.3.2 Geogebra Tips
Introduction.
Interactive and animated geogebra diagrams may be included. In the PDF version they will render as a static image with a QR code link to the web version.
Warning: Unintentional line breaks in the script will break it, and strings must be quoted with double-quotes. I believe that if you have a commmand which throws an error, the remaining instructions are not executed
Keep width of geogebra diagrams ~< 565 px to avoid scroll bars.
in slate command:
No semicolons between commands
Fitting
- You you can use evalCommand('ZoomIn(xmin, ymin,xmax,ymax)') to size image to match aspect ratio.
- enableShiftDragZoom(false)
- enableRightClick(false)
- recalculateEnvironment() Supposed to fit applet to environment. GGB API say it is recalculateEnvironments() but the version ending with 's' doesn't seem to work
To get text elements to fit properly, set everything to absolute position on screen, resize geogebra window to size of window in pretext, then place all the elements where you want them. Fix, and prevent selection as necessary.
GeoGebra: modified from ggb
file.
Vectors in space.
Shear and bending moment diagrams.
2-D Vector addition.
Type this in the input box.
-
a = (2,1)
This creates a vector from its \(x\) and \(y\) components. -
b = (2;120°)
This creates a vector from its magnitude and direction. You must include the degree sign°
; if you don't then the angle will be assumed to be in radians. TypingOption–o
or >Alt–o
will produce a degree sign. -
r = a + b
This produces the resultant vector.
- In Geogebra, use a comma to separate rectangular components and a semicolon to separate magnitude and direction.
- Lower case variables are vectors by default, and uppercase variables produce points.
- You can scroll the graphing window with your mouse or zoom out or in with a scroll wheel.
Animation.
Subsection C.3.3 Images
The preferred image types for the book for diagrams or drawings is Scalable Vector Graphics. This format should be used for any diagrams or drawings you make if possible. SVG
files can be created with Inkscape, Geogebra, or other tools and can easily and accurately be converted to pdf documents. For photographs use Portable Network Graphics images (extension .png
) if possible in preference to JPEG
files. Any diagram you create should have an 'actual' height of about 100 mm or 4 inches, or taller if necessary, but not more that 1 page tall. Diagrams will get scaled down when they go into the book. On the web version, clicking on the scaled image will pop up a larger image.
You will need to create or obtain a image file and store it with the PreTeXt source.
Store all image files in the resources directory, in your chapter folder, and then in a folder named for the image. It's a good idea to include a text file in this directory with the copyright and source info for crediting the image. See Best Practices for Attribution. All ggb
, jpg
, png
, svg
, pdf
and pdf_tex
files will be copied from here to a common images folder for inclusion into the document. This way, images can be inserted by using their filename only. Since all images will be in the same folder, no path is necessary, but all filenames must be unique so avoid common names like fbd.svg
.
There are several ways to include the images into the book.
Good. If you want to place an image with no caption, and no number, then you must wrap an <image>
tag with a <sidebyside>
tag, as so:
<sidebyside> <image source='filename.ext' width=75%' /></sidebyside>
You will also need to save the actual image file in the resources directory, from where it will be copied to the output. See the Pretext Docs for info on the sidebyside options.
If you want the image to have a caption and a number, wrap the <image>
tag with a <figure>
tag instead and give it a <title>
.
Better. Include a svg image for html and an identical pdf diagram for LaTeX.
This produces better quality than method 1, because both svg
and pdf
files are vector based and therefore will scale properly if the document shrinks or grows. In this case you will need to create both files. Inkscape will read either, and export the other, so it is not difficult to produce both. Save both files in the resources directory. Note there is no extension included in the source attribute. PreTeXt will include the proper image for html in the html file and for LaTeX in the latex file.
In this case the command to include the image is the same as before, but leave off the three letter extension. PreTeXt will select svg
for html and pdf
for LaTeX.
<image source='filename' width=75%' />
PreTeXt/LaTeX can overlay text on top of a static image, so that the font matches the body text, and LaTeX formulas can be used in the diagram.
To do this you will need to create or edit an image using Inkscape or some other tool. In any event, open the svg
file with Inkscape, and edit any text as necessary. LaTeX can be included in your labels, and colors and bold, and italic will be maintained but the text will use the document font. For annotated photographs, create a svg
file and import the the png image, then use the SVG tools to add text and arrows, etc. Geogebra can export 2D files as svg
. My CAD program doesn't natively export SVG
files, but I can "print as pdf" and convert that file to an editable svg
file using the command line tool pdf2svg
.
When you are finished editing the svg
file with Inkscape, save it as a svg
file and also "save as pdf". Choose the option "omit text in pdf and create LaTeX file." and save this in the same directory. Alongside your svg
image, two other files will be created, a pdf
file with no text, and a pdf_tex
file which is a standalone LaTeX file which overlays properly rendered text on top of the pdf
image.
The incantation to include this file is
<image> <latex-image> \pdftex[12pt]{filename} </latex-image> </image>
The font side argument [12pt] is optional, but can be used to adjust the default size if necessary.
In Affinity designer, use 72 dpi and built-in fonts and latexit font sizes will agree:
Use Times to match body font
Use CMU fonts to match latex
When unscaled, 16 point font matches body font. as in first diagram. Here the original size was 300px by 300 px, and it was inserted at 50% width which is also 300 px. Lesson: if you know how wide the diagram will be in the book, draw it at that size and use 16 point fonts to match body text.
In second diagram the 300 px wide original is inserted at 100% which is 600 px, so doubled. Now every font is too big. Need to use a 8 pt font to double to 16 pt, I think.
Example.
Here's an example of a svg
image with text rendered by latex overlaid. The composite image was saved as an svg
file, then a copy was saved as a pdf
file without text, along with balloon.pdf_tex
which was included in the source ptx as shown.
This image was composed of three parts,
- The x-z plane and the three ropes were drawn in Geogebra, and a screenshot was used to capture the image as a png. For 2D drawings Geogebra can export svg or png directly.
- The balloon was a png image.
- Both were imported into a svg image in Inkscape, where the axis labels, point labels, and the height were added with the text tool. The dotted line, and the dimension arrows were drawn in using Inkscape's tools.
If you look in the ptx/resources/ch03/balloon directory you will find all the intermediate files I used They are:
- chap_2_P8.png Jacob's original diagram
- balloononly.png The Balloon image without the lines or the dimensions, which I pulled and cleaned up from the original with photoshop.
- background.ggb A Geogebra file which I made to draw the ground plane and the cables.
- background.png The exported images from geogebra. Unfortunately Geogebra won't export 3d diagrams as svg, so I used png.
- balloon.svg A composite diagram I made in inkscape combining ballooononly.png and background.png and latex labels.
- balloon.pdf This file is the image without text, as exported from Inkscape.
- balloon.pdf_tex This file contains the instructions for the text and where to place it on top of balloon.pdf.
When PreTeXt Generates the book it makes a pdf file which composites the text on top of the ballon and inserts it into the Latex version of the book, and it also uses pdf2svg to make an SVG version to use for the web version.
More Info.
https://castel.dev/post/lecture-notes-2/
Multipage PDFs need all text on top layer
Troubleshooting Latex Images.
when running make images, if it doesn't complete
Check that the path to the images in docinfo is correct.
LaTeX Error: Cannot determine size of graphic in ... (no BoundingBox)
This error probably means that you are trying to us an SVG file in latex. Needs to be PDF.
I that's not it you can find the latex log file in the temporary folder created by the pretext script
set the -vv flag on the pretext/pretext script to get the path to the temporary folder
Inside that will be an image-nn.tex and image-nn.log files left behind by the failed conversion.
Info in the log file may tell you where the problem is.
Compiling the image-nn.tex file will also help. This calls the image.pdf_tex file which it needs access to, and will probably be where the problem actually is.
My latex macro \cm{40} worked, but \m{0.4} was being split into two parts by \m{0 and .4} by inkscape, I think and I don't know why.
Latex images seem to be more trouble than they're worth.
Subsection C.3.4 Exercise for Examples
<exercise>
<p>
<exercise>
-
<statement>
<p>
<hint>
<answer>
<solution>
<exercise>
<introduction>
-
<task>
<statement>
<hint>
<answer>
<solution>
<task>
<task>
<conclusion>
<exercise>
<introduction>
-
<task>
<introduction>
-
<task>
<statement>
<hint>
<answer>
<solution>
<conclusion>
<task>
-
<task>
<conclusion>
<conclusion>
investigation
prelude?
statement
Hint?
answer?
solution*
postlude
investigation
prelude?
introduction?
task+
conclusion?
postlude?
task
statement
hint?
answer?
solution?
task
introduction?
task+
solution?
task unstructured
Subsection C.3.5 Issues or questions for the developers
Issues with pretext
- Can't put bare image in, need to wrap with sidebyside.?
- Maybe use intro conclusion of task.
- Can't have an intro and a statement in investigations.
- How do I make a qed?
- I want bold for double emphasis or highlight
<alert>
?. - Need better support of multi-step solutions
- I'd like a procedure element.
- maybe allow tasks in
<solutions>
for the steps - task needs title
- allow paragraphs elements in
<solutions>
for lightweight divisions - Cant have a discussion within the task about multiple solutions
- Steps need to permit hints
- Would like to change the numbering of tasks/subtasks. Start with numbers, then letters, no bold. Would like a bold run in title though
- Schema doesn't permit
<paragraphs>
in solution, but it seems to render. - Can I have an inline list? a. one, b. two, c. three
- Intertext between mrows? I think so
-
<li>
permits<title>
Didn't know that. Couldn't find it in the documentation -
<kbd>
is in documentation but not in schema, I think - How can I change the chunking for
<exercises>
I'd like one numbas problem per page.