Cantera / cantera-website

Official Cantera Website
https://cantera.org
Other
14 stars 26 forks source link

"Caps" typogrify filter in Nikola is breaking rendering of LaTeX with strings of capital letters. #128

Closed rwest closed 3 years ago

rwest commented 3 years ago

I notice in the release notes of Nikola 8.1.2 "Restore caps typogrify filter (wraps strings of capital letters with <span class="caps"> (via Issue #3405)".

This is being applied to things like RT and AB which then breaks the mathjax rendering and screws up all the LaTeX math for any equations with two or more consecutive capital letters.

Screen Shot 2021-02-05 at 10 57 01 AM

Screenshot of documentation page https://cantera.org/science/reactions.html attached. OK math in green, broken math in red, with the offending letters circled. Same in Safari and Chrome.

Screen Shot 2021-02-05 at 10 52 05 AM

I don't know enough about Nikola to turn off this filter, but I think that's the problem.

rwest commented 3 years ago

I guess Kyle's solution in https://github.com/Cantera/cantera-website/pull/126 was to put a space in the letters so RT is R T. That would solve the problem for RT, but seems a bit fragile, and isn't going to look good for the diatomic molecule AB.

bryanwweber commented 3 years ago

Thanks for pointing this out @rwest! I think the change goes in the FILTERS dictionary in conf.py (line 701), where filters.typogrify should become filters.typogrify_custom(ignore_tags=("title" "div.math")). I'm not sure that'll work, but that's my best guess based on their documentation. Another thing to try would be to change filters.typogrify to "filters.typogrify_custom(%s, ignore_tags=('title', 'div.math'))", if the first one doesn't work.

Care to take a shot at it?

kyleniemeyer commented 3 years ago

The solution I found didn't actually change the display, since LaTeX doesn't care about spaces—it was just affecting the parser, for some reason. So, that might work here too.

rwest commented 3 years ago

True, A B will still render the same in the end, but will be confusing to anyone reading or writing the source, and easily forgotten in future edits. I think disabling the filter is a nicer solution.

12Chao commented 3 years ago

Hi @bryanwweber, I tried filters.typogrify_custom(ignore_tags=("title" "div.math")) but I got error:

[2021-02-05 15:32:04] ERROR: Nikola: "conf.py" cannot be parsed.
Traceback (most recent call last):
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/__main__.py", line 127, in main
    spec.loader.exec_module(conf)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "conf.py", line 701, in <module>
    FILTERS = {".html": [filters.typogrify_custom(ignore_tags=("title", "div.math")), filters.add_header_permalinks]}
TypeError: f_in_file() missing 1 required positional argument: 'fname'

For filters.typogrify_custom(%s, ignore_tags=('title', 'div.math')), the error looks like:

(chemcheck_env) chao@DESKTOP-J91MJLO:~/cantera-website$ nikola build
[2021-02-05 15:38:28] ERROR: Nikola: "conf.py" cannot be parsed.
Traceback (most recent call last):
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/__main__.py", line 127, in main
    spec.loader.exec_module(conf)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "conf.py", line 701, in <module>
    FILTERS = {".html": [filters.typogrify_custom("s%",ignore_tags=("title", "div.math")), filters.add_header_permalinks]}
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/filters.py", line 93, in f_in_file
    with io.open(fname, 'r', encoding='utf-8-sig') as inf:
FileNotFoundError: [Errno 2] No such file or directory: 's%'

I also tried FILTERS = {".html": [filters.typogrify_custom('pages/sicence/reactions.rst', ignore_tags=("title", "div.math")), filters.add_header_permalinks]}, then I got error

[2021-02-05 15:40:26] ERROR: Nikola: "conf.py" cannot be parsed.
Traceback (most recent call last):
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/__main__.py", line 127, in main
    spec.loader.exec_module(conf)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "conf.py", line 701, in <module>
    FILTERS = {".html": [filters.typogrify_custom("pages/science/reactions.rst",ignore_tags=("title", "div.math")), filters.add_header_permalinks]}
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/filters.py", line 95, in f_in_file
    data = f(data, *args, **kwargs)
TypeError: typogrify_custom() missing 1 required positional argument: 'typogrify_filters'

It seems like it requires at least 2 inputs as shown in Nikola documentation nikola.filters.typogrify_custom(data, typogrify_filters, ignore_tags=None), and I'm not sure how to specify the typogrify_filters input.

bryanwweber commented 3 years ago

Thanks @12Chao can you specify the list of filters on the readme here under the typogrify category? https://github.com/mintchaos/typogrify I think it should be a list of strings as that missing argument

12Chao commented 3 years ago

Thanks for the hint, I tried to change the Filters in conf.py to

from nikola import filters
import typogrify.filters as typo

FILTERS = {".html": [filters.typogrify_custom('pages/science/reactions.rst',[typo.amp, typo.smartypants, typo.caps, typo.initial_quotes],('title','div.math')), filters.add_header_permalinks]}

which is the way they call _run_typogrify in their source code but I got another error during Nikola build

Scanning posts..........done!
.  render_sources:output/science/reactions.rst
.  process_ref_targets:timeline_changes
.  process_ref_targets:pages/science/reactions.rst
.  process_ref_targets:pages/tutorials/ck2yaml-tutorial.rst
.  process_ref_targets:pages/tutorials/ck2cti-tutorial.rst
.  process_ref_targets:pages/science/species.rst
.  process_ref_targets:pages/science/flames.rst
.  process_ref_targets:pages/affiliated.rst
.  process_ref_targets:pages/tutorials/yaml/species.rst
.  process_ref_targets:pages/tutorials/yaml/yaml-format.rst
.  process_ref_targets:pages/tutorials/yaml/phases.rst
.  process_ref_targets:pages/tutorials/yaml/reactions.rst
.  process_ref_targets:pages/tutorials/legacy2yaml-tutorial.rst
.  process_ref_targets:pages/tutorials/yaml/defining-phases.rst
.  process_ref_targets:pages/tutorials/input-files.rst
.  process_ref_targets:pages/tutorials/cxx-guide/thermo.rst
.  process_ref_targets:pages/tutorials/cxx-guide/headers.rst
.  process_ref_targets:pages/tutorials/cxx-guide/index.rst
.  process_ref_targets:pages/tutorials/cxx-guide/simple-example.rst
.  process_ref_targets:pages/tutorials/cxx-guide/equil-example.rst
.  process_ref_targets:pages/tutorials/cxx-guide/factories.rst
.  process_ref_targets:pages/tutorials/cxx-guide/compiling.rst
.  process_ref_targets:pages/tutorials/cti/reactions.rst
.  process_ref_targets:pages/tutorials/cti/species.rst
.  process_ref_targets:pages/tutorials/cti/defining-phases.rst
.  process_ref_targets:pages/tutorials/cti/phases.rst
.  process_ref_targets:pages/tutorials/cti/cti-processing.rst
.  process_ref_targets:pages/tutorials/cti/cti-syntax.rst
.  process_ref_targets:pages/tutorials/MatlabTutorial.rst
.  process_ref_targets:pages/tutorials/PythonTutorial.rst
.  process_ref_targets:pages/science/reactors.rst
.  process_ref_targets:pages/science/phases.rst
.  process_ref_targets:pages/examples/index.rst
.  process_ref_targets:pages/governance.rst
.  process_ref_targets:pages/documentation/glossary.rst
.  process_ref_targets:pages/compiling/special-cases.rst
.  process_ref_targets:pages/dave-goodwin.rst
.  process_ref_targets:pages/compiling/installation-reqs.rst
.  process_ref_targets:pages/compiling/source-code.rst
.  process_ref_targets:pages/compiling/configure-build.rst
.  process_ref_targets:pages/compiling/dependencies.rst
.  process_ref_targets:pages/compiling/config-options.rst
.  process_ref_targets:pages/compiling/configure-build-dev.rst
[2021-02-05 17:14:41] WARNING: process_ref_targets: Duplicate label sec-build-commands, other instance in /compiling/configure-build.html
.  process_ref_targets:pages/community.rst
.  process_ref_targets:pages/compiling/config-options-dev.rst
.  process_ref_targets:pages/install/gentoo-install.rst
.  process_ref_targets:pages/install/install.rst
.  process_ref_targets:pages/install/other-linux-install.rst
.  process_ref_targets:pages/install/compiling-install.rst
.  process_ref_targets:pages/install/conda-install.rst
.  process_ref_targets:pages/install/macos-install.rst
.  process_ref_targets:pages/install/ubuntu-install.rst
.  process_ref_targets:pages/install/windows-install.rst
.  process_ref_targets:pages/science/index.rst
.  process_ref_targets:pages/tutorials/index.rst
.  process_ref_targets:/tmp/tmprafdvgyw/elements.rst
.  process_ref_targets:/tmp/tmprafdvgyw/general.rst
.  process_ref_targets:/tmp/tmprafdvgyw/index.rst
.  process_ref_targets:/tmp/tmprafdvgyw/phases.rst
.  process_ref_targets:/tmp/tmprafdvgyw/reactions.rst
.  process_ref_targets:/tmp/tmprafdvgyw/species.rst
.  render_taxonomies:output/authors/index.html
TaskError - taskid:render_taxonomies:output/authors/index.html
PythonAction Error
Traceback (most recent call last):
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/doit/action.py", line 437, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/utils.py", line 978, in unlessLink
    subprocess.check_call(action % target, shell=True)
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'

########################################
render_taxonomies:output/authors/index.html <stdout>:
bryanwweber commented 3 years ago

I think that first argument needs to be "%s" not a specific file

12Chao commented 3 years ago

with FILTERS = {".html": [filters.typogrify_custom("%s",[typo.amp, typo.smartypants, typo.caps, typo.initial_quotes],('title','div.math')), filters.add_header_permalinks]}, I got FileNotFoundError

[2021-02-05 17:49:53] ERROR: Nikola: "conf.py" cannot be parsed.
Traceback (most recent call last):
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/__main__.py", line 127, in main
    spec.loader.exec_module(conf)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "conf.py", line 702, in <module>
    FILTERS = {".html": [filters.typogrify_custom("%s",[typo.amp, typo.smartypants, typo.caps, typo.initial_quotes],('title','div.math')), filters.add_header_permalinks]}
  File "/home/chao/anaconda3/envs/chemcheck_env/lib/python3.8/site-packages/nikola/filters.py", line 93, in f_in_file
    with io.open(fname, 'r', encoding='utf-8-sig') as inf:
FileNotFoundError: [Errno 2] No such file or directory: '%s'
bryanwweber commented 3 years ago

My reading of the comment right above the FILTERS is that if you're using the string version, you need %s. Otherwise your should omit it. Could be wrong though 😁 you might need to dig in to how the filters are loaded in Nikola to see how the arguments are used

bryanwweber commented 3 years ago

This was fixed by removing the typogrify filter altogether.