Pretext Script and Images

179 views
Skip to first unread message

Roc...@wcsu.edu

unread,
Feb 22, 2021, 7:50:54 PM2/22/21
to PreTeXt support
If I run the following

pretext -vv build -i src/Intro_Crypto_Main.ptx -p src/publication.xml -d output html

HTML output is generated fine but only SVG images are created for the latex images.

Trying to follow previous conversations I tried the output posted below, but go an error after it created a tex file, pdf, and svg for one image.

Suggestions I am open to suggestions.  I am running Windows 10 and I think I have all the necessary components installed.

$ python c:/git/mathbook/pretext/pretext -vv -c latex-image -f all -d tmp_images src/Intro_Crypto_Main.ptx
Invalid Parameter - 300
PTX:DEBUG: Parsed CLI args {'verbose': 2, 'component': 'latex-image', 'format': 'all', 'publisher_file': None, 'stringparams': [], 'xmlid': '', 'server': None, 'data_dir': None, 'out': None, 'dir': 'tmp_images', 'abort': False, 'xml_file': 'src/Intro_Crypto_Main.ptx'}
PTX:DEBUG: Python version: 3.7 (expecting 3.4 or newer)
PTX:DEBUG: discovered distribution and xsl directories: c:\git\mathbook, c:\git\mathbook\xsl
PTX:DEBUG: executables in configuration file: {'tex': 'xelatex', 'pdfsvg': 'pdf2svg', 'asy': 'asy', 'sage': 'sage', 'pdfpng': 'convert', 'pdfeps': 'pdftops', 'pdfcrop': 'pdf-crop-margins', 'pageres': 'pageres', 'node': 'node', 'liblouis': 'file2brl'}
PTX: verifying and expanding input directory: tmp_images
PTX: input directory expanded to absolute path: C:\git\Inquiry-Into-Cryptology\tmp_images
PTX: verifying and expanding input file: src/Intro_Crypto_Main.ptx
PTX: input file expanded to absolute path: C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx
PTX: Done examining environment and initializing setup info
PTX: converting latex-image pictures from C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx to all graphics for placement in C:\git\Inquiry-Into-Cryptology\tmp_images
PTX:DEBUG: temporary directory for latex-image conversion: C:\Users\roccac\AppData\Local\Temp\tmpt4re20nu
PTX: extracting latex-image pictures from C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx
PTX: string parameters passed to extraction stylesheet: {}
PTX: XSL conversion of C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx by c:\git\mathbook\xsl\extract-latex-image.xsl
PTX:DEBUG: XSL conversion via c:\git\mathbook\xsl\extract-latex-image.xsl of C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx to None and/or into directory C:\Users\roccac\AppData\Local\Temp\tmpt4re20nu with parameters {}
PTX:DEBUG: locating "tex" in [executables] section of configuration file
PTX:DEBUG: tex executable: xelatex, options:
PTX:DEBUG: tex executable: xelatex
PTX: converting image-1.tex to image-1.pdf
PTX:DEBUG: locating "pdfcrop" in [executables] section of configuration file
PTX:DEBUG: pdfcrop executable: pdf-crop-margins, options:
PTX: cropping image-1.pdf to image-1.pdf
PTX:DEBUG: locating "pdfsvg" in [executables] section of configuration file
PTX:DEBUG: pdfsvg executable: pdf2svg, options:
PTX:DEBUG: pdfsvg executable: pdf2svg
PTX: converting image-1.pdf to image-1.svg
PTX:DEBUG: locating "pdfpng" in [executables] section of configuration file
PTX:DEBUG: pdfpng executable: convert, options:
PTX:DEBUG: pdfpng executable: convert
PTX: converting image-1.pdf to image-1.png
Traceback (most recent call last):
  File "c:/git/mathbook/pretext/pretext", line 302, in <module>
    main()
  File "c:/git/mathbook/pretext/pretext", line 244, in main
    ptx.latex_image_conversion(xml_source, publisher_file, stringparams, args.xmlid, data_dir, dest_dir, args.format)
  File "c:\git\mathbook\pretext\pretext.py", line 301, in latex_image_conversion
    shutil.copy2(latex_image_png, dest_dir)
  File "C:\Program Files\Python37\lib\shutil.py", line 263, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:\Program Files\Python37\lib\shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'image-1.png'

Alex Jordan

unread,
Feb 22, 2021, 7:58:49 PM2/22/21
to pretext...@googlegroups.com
Can you first get the .pdf image, and then manually try the pdf->png
conversion that pretext uses? My guess is that this is failing for
some reason, and if you try it manually, you will see helpful error
messages. The command to try is:

convert -density 300 image-1.pdf -quality 100 image-1.png

once you have that image-1.pdf.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/71589470-5460-449d-8b41-a85fdb117d0an%40googlegroups.com.

Sean Fitzpatrick

unread,
Feb 22, 2021, 9:53:29 PM2/22/21
to pretext...@googlegroups.com
The "Invalid parameter -300" line sounds like a hint that the pdf to png converter is either not installed, or not the one that is expected.

Roc...@wcsu.edu

unread,
Feb 23, 2021, 9:23:33 AM2/23/21
to PreTeXt support
Creating the PDFs first and then converting worked.  This leaves me with two questions.

First, how do I get wild cards to work with convert?  Using "convert -density 300 *.pdf -quality 100 *.png" or variations on that did not work as desired.

Second, what should I look for in my configuration to try and get the image creation to work as expected with "python c:/git/mathbook/pretext/pretext -vv -c latex-image -f all -d tmp_images src/Intro_Crypto_Main.ptx" ?  Is this likely an issue with my installation of ImageMagick?

Sean Fitzpatrick

unread,
Feb 23, 2021, 11:35:19 AM2/23/21
to pretext...@googlegroups.com
On Windows, you could install Git Bash to run Bash commands. (Maybe this is possible in PowerShell but I don't know it very well.)

Then you could do something like

`for file in *.pdf; do convert -density 300 "$file" -quality 100 "{$file%.*}.png"; done`

another option might be to use the `mogrify` command from ImageMagick.

Below is for png to jpg conversion, but same idea:

https://superuser.com/questions/71028/batch-converting-png-to-jpg-in-linux
--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.

Roc...@wcsu.edu

unread,
Feb 23, 2021, 1:13:58 PM2/23/21
to PreTeXt support
Okay, I got that working in git bash and after poking around on ImageMagick's web at some of their examples I got 

FOR %a in (*.pdf) DO convert -density 300 %a -quality 100 %~na.png

to work at a command prompt in Windows, in case anyone else needs it.

Thanks! 

Rob Beezer

unread,
Feb 23, 2021, 1:28:15 PM2/23/21
to pretext...@googlegroups.com
On 2/23/21 6:23 AM, Roc...@wcsu.edu wrote:
> Second, what should I look for in my configuration to try and get the image
> creation to work as expected with "python c:/git/mathbook/pretext/pretext -vv -c
> latex-image -f all -d tmp_images src/Intro_Crypto_Main.ptx" ?  Is this likely an
> issue with my installation of ImageMagick?

Glad to see you have a workaround now. But I'd love to understand why the
script was failing for you. Since it will fail for others, potentially.
Suggestions:

1. In pretext/pretext.cfg (copied to a personal version) change to

pdfpng = /full/path/from/root/convert

to see if somehow the executable is not being found?

2. In -vv output you will see

PTX:DEBUG: temporary directory for latex-image conversion:
C:\Users\roccac\AppData\Local\Temp\tmpt4re20nu

but with a different temp directory on each run.

This directory is normally trashed, but preserved iff -vv is used.

cd to that directory and try running the convert command in various ways
(different path, different shell,...) to make it fail (or succeed).

Thanks,
Rob



Roc...@wcsu.edu

unread,
Feb 23, 2021, 5:34:30 PM2/23/21
to PreTeXt support
Not sure I was fully understanding what you were looking for in the last line, but this is what I tried

All of these work fine in both git bash and at the command prompt in a DOS window
  • python c:/git/mathbook/pretext/pretext -vv -c latex-image -f pdf -d tmp_images_test src/Intro_Crypto_Main.ptx
  • python c:/git/mathbook/pretext/pretext -vv -c latex-image -f svg -d tmp_images_test src/Intro_Crypto_Main.ptx
  • python c:/git/mathbook/pretext/pretext -vv -c latex-image -f eps -d tmp_images_test src/Intro_Crypto_Main.ptx
  • convert ../*.pdf -adjoin image.gif (this created an animated gif of all the latex-images in the text, it was a little weird but worked)
  • convert ../*.pdf image.png (though the naming is not consistent with the pdf files.)
  • convert *.pdf *.png (though the naming is not consistent with the pdf files.)
  • convert image-42.pdf tmp/image.png

But when I run 
  • python c:/git/mathbook/pretext/pretext -vv -c latex-image -f all -d tmp_images_test src/Intro_Crypto_Main.ptx
the temporary directory has all the .tex files then only image-1.pdf, image-1.png, image-1.aux, and image-1.log.

When I run
  • python c:/git/mathbook/pretext/pretext -vv -c latex-image -f png -d tmp_images_test src/Intro_Crypto_Main.ptx
I get the same result without the svg file.

Here is the output from the last run where I tried compiling the png files.

$ python c:/git/mathbook/pretext/pretext -vv -c latex-image -f png -d tmp_images_test src/Intro_Crypto_Main.ptx
PTX:DEBUG: Parsed CLI args {'verbose': 2, 'component': 'latex-image', 'format': 'png', 'publisher_file': None, 'stringparams': [], 'xmlid': '', 'server': None, 'data_dir': None, 'out': None, 'dir': 'tmp_images_test', 'abort': False, 'xml_file': 'src/Intro_Crypto_Main.ptx'}
PTX:DEBUG: Python version: 3.7 (expecting 3.4 or newer)
PTX:DEBUG: discovered distribution and xsl directories: c:\git\mathbook, c:\git\mathbook\xsl
PTX:DEBUG: executables in configuration file: {'tex': 'xelatex', 'pdfsvg': 'pdf2svg', 'asy': 'asy', 'sage': 'sage', 'pdfpng': '/full/path/from/root/convert', 'pdfeps': 'pdftops', 'pdfcrop': 'pdf-crop-margins', 'pageres': 'pageres', 'node': 'node', 'liblouis': 'file2brl'}
PTX: verifying and expanding input directory: tmp_images_test
PTX: input directory expanded to absolute path: C:\git\Inquiry-Into-Cryptology\tmp_images_test
PTX: verifying and expanding input file: src/Intro_Crypto_Main.ptx
PTX: input file expanded to absolute path: C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx
PTX: Done examining environment and initializing setup info
PTX: converting latex-image pictures from C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx to png graphics for placement in C:\git\Inquiry-Into-Cryptology\tmp_images_test
PTX:DEBUG: temporary directory for latex-image conversion: C:\Users\roccac\AppData\Local\Temp\tmpdb4rlblb
PTX: extracting latex-image pictures from C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx
PTX: string parameters passed to extraction stylesheet: {}
PTX: XSL conversion of C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx by c:\git\mathbook\xsl\extract-latex-image.xsl
PTX:DEBUG: XSL conversion via c:\git\mathbook\xsl\extract-latex-image.xsl of C:\git\Inquiry-Into-Cryptology\src\Intro_Crypto_Main.ptx to None and/or into directory C:\Users\roccac\AppData\Local\Temp\tmpdb4rlblb with parameters {}
PTX:DEBUG: locating "tex" in [executables] section of configuration file
PTX:DEBUG: tex executable: xelatex, options:
PTX:DEBUG: tex executable: xelatex
PTX: converting image-1.tex to image-1.pdf
PTX:DEBUG: locating "pdfcrop" in [executables] section of configuration file
PTX:DEBUG: pdfcrop executable: pdf-crop-margins, options:
PTX: cropping image-1.pdf to image-1.pdf
PTX:DEBUG: locating "pdfpng" in [executables] section of configuration file
Traceback (most recent call last):
  File "c:/git/mathbook/pretext/pretext", line 302, in <module>
    main()
  File "c:/git/mathbook/pretext/pretext", line 244, in main
    ptx.latex_image_conversion(xml_source, publisher_file, stringparams, args.xmlid, data_dir, dest_dir, args.format)
  File "c:\git\mathbook\pretext\pretext.py", line 295, in latex_image_conversion
    pdfpng_executable_cmd = get_executable_cmd('pdfpng')
  File "c:\git\mathbook\pretext\pretext.py", line 1681, in get_executable_cmd
    raise OSError('\n'.join(error_messages))
OSError: PTX:ERROR: cannot locate executable with configuration name `pdfpng` as command `/full/path/from/root/convert`
*** Edit the configuration file and/or install the necessary program ***

Alex Jordan

unread,
Feb 23, 2021, 5:38:51 PM2/23/21
to pretext...@googlegroups.com
It looks like you took Rob literally, and put:
/full/path/from/root/convert
into your config file.

What he meant was to find the place where the convert executable lives
on that system. This command:
which convert
might show you where it is. And then put that full path into the config file.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/70cc7c81-55ff-4372-814f-078c070d138en%40googlegroups.com.

Roc...@wcsu.edu

unread,
Feb 24, 2021, 7:32:10 AM2/24/21
to PreTeXt support
Well, that makes more since now.  I thought "/full/path/from/root/convert" might be a piece of script that I just didn't know.

Unfortunately that didn't change the result.  

I also double checked my PATH on my computer and ImageMagick is there.

How sensitive is all of this to versions?  I see that the most recent version of ImageMagick is 7.0.11 while I have 7.0.10.

Thanks for the correction.


PTX:DEBUG: locating "pdfpng" in [executables] section of configuration file
Traceback (most recent call last):
  File "c:/git/mathbook/pretext/pretext", line 302, in <module>
    main()
  File "c:/git/mathbook/pretext/pretext", line 244, in main
    ptx.latex_image_conversion(xml_source, publisher_file, stringparams, args.xmlid, data_dir, dest_dir, args.format)
  File "c:\git\mathbook\pretext\pretext.py", line 295, in latex_image_conversion
    pdfpng_executable_cmd = get_executable_cmd('pdfpng')
  File "c:\git\mathbook\pretext\pretext.py", line 1681, in get_executable_cmd
    raise OSError('\n'.join(error_messages))
OSError: PTX:ERROR: cannot locate executable with configuration name `pdfpng` as command `C:/ImageMagick-7.0.10-Q16-HDRI/convert`


Roc...@wcsu.edu

unread,
Feb 24, 2021, 3:12:57 PM2/24/21
to PreTeXt support
Update, perhaps I am just a little slow and this is what Rob meant before, but using 

pdfpng = C:/ImageMagick-7.0.10-Q16-HDRI/convert.exe

instead of 

pdfpng = C:/ImageMagick-7.0.10-Q16-HDRI/convert

seems to work.  Simply changing the original line to 

pdfpng = convert.exe

does not work.

Rob Beezer

unread,
Feb 24, 2021, 3:29:25 PM2/24/21
to pretext...@googlegroups.com
Right. (I shoulda remembered the Windows *.exe, I was speaking in Linux.)

So there is something about your system where the Python script is not "finding"
convert.exe without a complete path. I know you've consulted your PATH.

I'd say this is the fix (and *not* processing outside of the script). Be sure
you've followed the directions and put a personalized copy of pretext.cfg into
mathbook/user (and save a copy somewhere else?), or your next pull will go bad.

Holler if there is more to do on this one. Thanks for sorting it out.

Rob
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/68d56886-8488-4894-873a-86aad669dcb9n%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/68d56886-8488-4894-873a-86aad669dcb9n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages