KaTeX / KaTeX

Fast math typesetting for the web.
https://katex.org
MIT License
18.26k stars 1.17k forks source link

Build system does not fetch fonts when font-folder is modified #1987

Open danielhollas opened 5 years ago

danielhollas commented 5 years ago

Describe the bug: When you modify @font-folder in submodules/katex-fonts/fonts.less (per these instructions), the build system will no longer find them in submodules/katex-fonts/fonts/ and the dist/fonts/ folder will be missing in the build. Two-step process is needed in this case:

  1. Build with default fonts.less file, and copy dist/fonts/ folder where you need.
  2. Modify fonts.less and build again to get correct katex.min.css file.

To Reproduce: Steps to reproduce the behavior:

  1. Modify @font-folder in submodules/katex-fonts/fonts.less
  2. yarn build
  3. dist/ folder will not contain fonts

Expected behavior: IMO fonts should be fetched regardless of the value of @font-folder

Additional context: I was rebuilding KaTeX for Discourse Math plugin, which requires:

@font-folder: "/plugins/discourse-math/katex/fonts";

danielhollas commented 5 years ago

Pulled my comments from #1976 to a separate issue per @edemaine request. :-)

edemaine commented 5 years ago

Not knowing Webpack super well, I thought I'd give a try at resolving this via pure less. What's wrong with the following approach?

npx lessc --modify-var='font-folder=new-location' src/katex.less custom-katex.css

P.S. I don't think this is a bug. It's pretty much how you'd expect all the parts to work...

danielhollas commented 5 years ago

I am not sure I understand your approach. What would you do with the custom-katex.css file? I have next-to-nothing knowledge of webpack as well, so I do not know whether the current behaviour can be improved or not. All I am saying is that I was mega-confused why I was not getting my fonts in the build process.

kevinbarabash commented 5 years ago

@danielhollas I'd like to try reproducing this. What did you change the @font-folder to in step 1?

kevinbarabash commented 5 years ago

Also, where can I find the source for the discourse plugin? Perhaps there's a change that could be made to that setup. We're in the process of changing how we ingest new KaTeX versions at KA and as part of that we've updated our webpack config using file-loader to rewrite the paths for the font files as well as copy them to new location from within node_modules.

danielhollas commented 5 years ago

@kevinbarabash thanks for looking into this! Here's what I have: @font-folder: "/plugins/discourse-math/katex/fonts";

Here's the plugin: https://github.com/discourse/discourse-math KaTeX files are in public/katex and the loading code is here.

Discourse has its own custom plugin system which I, unfortunately, do not understand in detail. But somehow the way the plugin assets are loaded screws up the relative path to fonts that is in normal katex.css. For example, if I am in a topic on the forum with this URL: "/t/slug/topic_id/ the relative path to fonts then results in 404 on the address: "/t/slug/topic_id/fonts/Katex-XXX.woff2"