Repository: getnikola/nikola

Issue:
Consecutive capitals in Math are labeled as span caps
<!--
Before creating an issue:
* make sure you are using an up-to-date version of Nikola
* search for existing issues that might be related

Make sure to:
* provide information about your environment (below)
* include all the output you get, and any other information related to your problem

Nikola v7.6.4, as provided by Ubuntu, is NOT SUPPORTED.
If you are using this version, you should upgrade: https://getnikola.com/getting-started.html
-->

### Environment

**Python Version:** 3.9.1

**Nikola Version:** 8.1.3

**Operating System:** macOS

### Description:

In Nikola 8.1.2, the `caps` typogrify filter was re-enabled. Unfortunately, consecutive capital letters in math mode (when enabled) also trigger the filter, resulting in broken equations. I think the simplest fix is to add the `.math` CSS class to the ignored tags here: https://github.com/getnikola/nikola/blob/c49f959a5b3ad7ee2c37491c68668bd441e0c918/nikola/filters.py#L272

Aside from that, in trying to debug this issue, I could not determine how to pass options to the `typogrify_custom` filter. `typogrify_custom` is the only filter wrapped by `apply_to_text_file` that has more than one argument, and it is not wrapped by the `_ConfigurableFilter` class to read an option from `conf.py`. In the end, I had to create a `functools.partial` in my `conf.py` that passed the list of `typogrify_filters` to apply as well as the modified `ignore_tags`.

If that's the intended interface, it would be nice to support a default list of applied filters, in case the user only wants to edit the `ignore_tags` (and vice-versa).

Please let me know if I should create a pull request with my suggested fix for the `.math` issue!

References:

https://github.com/Cantera/cantera-website/issues/128
https://github.com/getnikola/nikola/pull/3447/ (and linked issues)



Discussion:
> Please let me know if I should create a pull request with my suggested fix for the .math issue!

Sure, go ahead!

(This kinda depends on the project and the maintainers, but I personally prefer and recommend just creating minor/bugfix PRs without asking if they’re appropriate — worst case scenario, they’d get closed, but they are likely to just get accepted; note that policies differ in different projects; projects that mandate having a issue ticket first exist too.)

> In the end, I had to create a functools.partial in my conf.py that passed the list of typogrify_filters to apply as well as the modified ignore_tags.

This might be a bit complicated, but I don’t think many users would be interested in using `typogrify_custom` — note that it requires importing callables from typogrify, so it’s not that easy to configure, `functools.partial` aside. If you have any ideas on how this could be improved, preferably without adding configuration options, we can discuss them (here or in a PR with your implementation).

Resolving patch:
diff --git a/nikola/filters.py b/nikola/filters.py
--- a/nikola/filters.py
+++ b/nikola/filters.py
@@ -269,7 +269,7 @@ def minify_lines(data):
 def _run_typogrify(data, typogrify_filters, ignore_tags=None):
     """Run typogrify with ignore support."""
     if ignore_tags is None:
-        ignore_tags = ["title"]
+        ignore_tags = ["title", ".math"]
 
     data = _normalize_html(data)
 


Test patch: