PreTeXtBook / pretext-cli

Command line interface for quickly creating, authoring, and building PreTeXt documents.
https://pretextbook.org
GNU General Public License v3.0
17 stars 18 forks source link

Building with localization #77

Closed JeanSebastienTurcotte closed 3 years ago

JeanSebastienTurcotte commented 3 years ago

When a main.ptx has been modified to use a localization file, for instance fr-CA, the command pretext build html fails, giving the error below

Traceback (most recent call last): File "/home/user/.local/bin/pretext", line 8, in <module> sys.exit(main()) File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__ return self.main(*args, **kwargs) File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/user/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/home/user/.local/lib/python3.8/site-packages/pretext/cli.py", line 147, in build build.html(source,html_output,stringparams) File "/home/user/.local/lib/python3.8/site-packages/pretext/build.py", line 27, in html xsltproc(xslfile, ptxfile, outfile=None, outdir=output, stringparams=stringparams) File "/home/user/.local/lib/python3.8/site-packages/pretext/build.py", line 111, in xsltproc newdom = transform(dom, **stringparams) File "src/lxml/xslt.pxi", line 582, in lxml.etree.XSLT.__call__ File "src/lxml/etree.pyx", line 316, in lxml.etree._ExceptionContext._raise_if_stored lxml.etree.XSLTApplyError: Cannot resolve URI /home/user/.local/lib/python3.8/site-packages/pretext/static/xsl/localizations/fr-CA.xsl

rbeezer commented 3 years ago

Not 100% sure about the CLI, but normally the localization file is not an input to the process. Everything should be handled by the stylesheets in reaction to an @xml:lang attribute on the pretext element.

So I expect this file is not even present?

JeanSebastienTurcotte commented 3 years ago

When using pretext new with the CLI, the @xml:lang is not added to the pretext element. I added it manually but then 'build' does not know what to do with it, even if adding 'en-US'.

oscarlevin commented 3 years ago

I can confirm that fr-CA.xsl is not included in this distribution; this will be fixed in the next version. I don't know why en-US wouldn't work though.

JeanSebastienTurcotte commented 3 years ago

I probably made a mistake when I tried en-US, it does work. I'll use fr-FR for now.

StevenClontz commented 3 years ago

In 11facc0 we add @xml:lang="en-US" to newly generated documents.

I'll update rbeezer/mathbook resources now which I think closes this.

JeanSebastienTurcotte commented 3 years ago

Would it be hard/long to have a non mandatory option (say -l) that defaults to en-US if absent and otherwise lets the user choose one of the supported language? I'm thinking we'd need to maintaint a list to validate input and display an error message to avoid bad input.

StevenClontz commented 3 years ago

I'm thinking we'd need to maintaint a list to validate input and display an error message to avoid bad input.

This is my hesitation to include this in the 0.2 release we want out in the next week, but we could add this feature to 0.3. In the meantime users can edit the generated @xml:lang (a one-time step after pretext new).

This kind of touches on a design philosophy question: how much of a new pretext project do we want users to be able to specify using the CLI, and how much do we want them to express directly in their source after we take care of all the boilerplatey steps? Right now we have an interface to let users define a few chapters when they pretext new, but maybe that's not important enough to maintain vs. just having a couple chapters/sections generated in the boilerplate that users can edit/copy in source.

StevenClontz commented 3 years ago

Right now we have an interface to let users define a few chapters when they pretext new

Maybe this is backwards. An author is unlikely to know how many chapters they want in a new book when they first get started, but they probably do have a good idea of the language they want to write in.

JeanSebastienTurcotte commented 3 years ago

I agree that chapter on creation isn't a priority but it's already there.

Oftentimes I find what I thought would be a chapter turns out to be a section and the other way around is probably even more true.

Personally, aside from language, what I like to decide at the start is if my document will be a one file or will I have one file per section/chapter and use xi: include. Maybe there could be some sort of depthness wanted and some templates created accordingly.

StevenClontz commented 3 years ago

Some xi:include discussion is in #22, and I've opened #82 to discuss multiple source files on pretext new

StevenClontz commented 3 years ago

@JeanSebastienTurcotte can you install the bleeding-edge CLI using

python -m pip install git+https://github.com/pretextbook/pretext-cli.git

and check to see if your book builds correctly? Or let me know where I can clone your book to try this myself.

Once this is checked I'll close this. I've opened #83 to consider specifying non-en-US languages for pretext new in a future release.

JeanSebastienTurcotte commented 3 years ago

Everything is working now. Thank you