jupyter-book / mystmd

Command line tools for working with MyST Markdown.
https://mystmd.org/guide
MIT License
192 stars 62 forks source link

jtex: Allow for nested files structure #84

Closed kai-tub closed 1 year ago

kai-tub commented 1 year ago

Context

Hey, I would like to extract the individual issues discussed in https://github.com/kai-tub/latex-beamer-pure-minimalistic/discussions/75 for clarity and easier communication.

As discussed in the thread, I am more than happy to try to give my template first-class support for mystjs/jtex. As part of the first trial, I would strongly prefer not to be forced to have a flat file hierarchy when creating the template. My workflow would be as follows:

My reasoning is as follows:

Proposal

Allow the template.tex and template.yml files to be in a separate directory from the other theme components. Allow files to be in separate directories to not restrict the 'expected' structure of themes.

Please let me know if I should further clarify my points :)

Tasks and updates

No response

welcome[bot] commented 1 year ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

fwkoch commented 1 year ago

Hey @kai-tub - thanks for breaking this out into a bite-sized issue!

I agree that the same-directory requirement is arbitrary and unnecessarily restrictive. (Going through all your specific use-cases is great!) For now, I think this specifically applies only to the template.yml#files field? For example template.yml#thumbnail has no same-directory restriction.

A few minor points to work through:

Also worth noting we don't even respect these files when we copy template files: https://github.com/executablebooks/mystjs/blob/main/packages/jtex/src/jtex.ts#L244 - that just looks in the single template directory. As a part of this work, we need to change that to use files.

rowanc1 commented 1 year ago

Thanks @kai-tub for splitting this out of the discussion, very helpful! :)

Re @fwkoch's comments:

Probably just use / separator in template.yml which jtex resolves into system path.

I think we should probably even validate on unix-style path separators in the template.yml and then remap these on any client.

Do we allow for including entire folders? [glob patterns]

Agree that we can probably kick this down the road, my guess is that we could accelerate this with a jtex check command or something to explicitly add and check that the files exist.

kai-tub commented 1 year ago

Thanks for the quick responses! I will just throw in a couple of comments from my side.

For now, I think this specifically applies only to the template.yml#files field?

Yes.

I think we should probably even validate on unix-style path separators in the template.yml and then remap these on any client.

Yeah, I would 'expect' the UNIX-style path separator to be the most appropriate. Also, because this is the way Python (pathlib) and LaTeX expect 'path-strings' to be formatted.

Do we allow for including entire folders? [glob patterns]

I agree that this isn't as important right now. Themes and other LaTeX files usually do not have that many files flying around. But if there were glob pattern support, I would also need a way to exclude specific files that only exist for "documentation" purposes. And by that time, I might've just as well listed all files explicitly. So my vote is for: I personally do not expect glob patterns to exist and would put it at the bottom of the priority list.

Agree that we can probably kick this down the road, my guess is that we could accelerate this with a jtex check command or something to explicitly add and check that the files exist.

Sounds reasonable to me. Maybe there is a way to nicely present all files that jtex would include in a tree structure? Something like jtex check --files/tree or similar?

Do we need to allow template.tex in any folder?

Also agree that root directory for template.tex/yml makes sense :)

But just for clarification, I would still be able to select a file as:

- logos/logo.png

and then expect the file logo.png to be inside of a logos directory, correct?

fwkoch commented 1 year ago

@kai-tub - I took a pass at this with #89 - it's now deployed to NPM. Keen for you to give it a try and see if it helps out (or if you run into any problems)!

Closing the issue for now, but feel free to re-open if you need!

kai-tub commented 1 year ago

Yes @fwkoch, thanks! It works! :+1:

I've added everything to my template:

But something that I forgot was that Beamer usually 'expects' local themes to live on the same "hierarchy" level as the sty files.

So when I configure my template to use a subdirectory/submodule, then I need to be aware of this Beamer limitation and change my template.tex file to not use the \usetheme command but the \usepackage command with the correctly resolved name.

IMHO I still very much prefer to have the 'nested-file' option and manage it as a submodule. Even if this means that I need to deviate from the classic code.

Another side-effect of having the files at different hierarchy levels is that the default pictures/logos are relative to the rendered .tex file (which I also forgot, sorry :disappointed: ! ). So I had to manually duplicate the logo files to my template root. Which I do not have anything against! I have two reasons:

  1. I don't really mind having to duplicate this type of "dead" data, as I don't care what the logo looks like, and if it becomes "out-of-sync" with my "upstream" theme repository (I would not feel the same for the sty/tex files)
  2. I expect the end-user to use a custom logo either way, so they would have to manage this either way

Both of these things maybe do open up the discussion about the implementation, though:

Though I have a very specific workflow in mind (submodule for true source, adding template.yml/tex in other repo and calling it a day), maybe I am a bit biased towards the 'injection' solution? As I wrote above, there are solutions to work around the different hierarchy levels, so it is not a blocker, in my opinion.

I just wanted to give you my feedback :)

Sorry again for not seeing these issues/limitations before you implemented the feature :/

kai-tub commented 1 year ago

Yeah... So I looked a bit further into the issues I had when trying to get my docker environment (described in #97) running with a minimal environment, and I got bitten by the fact that an old version of my package exists on CTAN and that it was hiding an error by using files from installed packages... The issue is that when customizing a theme, one usually also customizes the font/color/inner/outer parts of the theme. And those are also resolved relative to the main tex file (template.tex) and not relative to the root sty file that describes the theme (when doing a local look-up).

So in my case, I would have to apply the following patch to the source of my beamer theme sty file if I want to keep the theme files inside a directory called latex-beamer-pure-minimalistic:

diff --git a/beamerthemepureminimalistic.sty b/beamerthemepureminimalistic.sty
index 87183b8..ffbe454 100644
--- a/beamerthemepureminimalistic.sty
+++ b/beamerthemepureminimalistic.sty
@@ -19,7 +19,7 @@
 % If problems/bugs are found or enhancements are desired, please contact
 % me over: https://github.com/kai-tub/latex-beamer-pure-minimalistic

-\ProvidesPackage{beamerthemepureminimalistic}[v2.0.3]
+\ProvidesPackage{latex-beamer-pure-minimalistic/beamerthemepureminimalistic}[v2.0.3]

 \mode<presentation>

@@ -33,10 +33,10 @@
 \ProcessOptionsBeamer

 % Settings
-\usefonttheme{pureminimalistic}
-\usecolortheme{pureminimalistic}
-\useoutertheme{pureminimalistic}
-\useinnertheme{pureminimalistic}
+\usepackage{latex-beamer-pure-minimalistic/beamerfontthemepureminimalistic}
+\usepackage{latex-beamer-pure-minimalistic/beamercolorthemepureminimalistic}
+\usepackage{latex-beamer-pure-minimalistic/beamerouterthemepureminimalistic}
+\usepackage{latex-beamer-pure-minimalistic/beamerinnerthemepureminimalistic}

 \setbeamertemplate{navigation symbols}{}%
 \beamerdefaultoverlayspecification{}

I wasn't aware of this issue because, in my quick tests, LaTeX simply looked up the theme files from my version from CTAN and used those instead of the files that I had locally...

So when I create a separate folder, I would still be required to touch the original theme repository, which I wanted to avoid by requesting this feature... I am really sorry that I wasn't aware of this Beamer limitation and that it is such a convoluted issue. :/

For further reference, one can also look into patching beamer code as described here:

but that also seems like a hack rather than a solution.

The nested file structure feature is still useful for template authors (I think) when they want to include local files like figures or similar relative to the template.tex file. But it seems to have no benefit for my suggested workflow with a git submodule.

So I guess the correct request for my submodule workflow would be to have an option that allows me to:

If I should clarify anything, please let me know! And sorry again for potentially leading you down the wrong path.