Repository: facelessuser/pymdown-extensions

Issue:
Arithmatex: removing dollar inline syntax gives "IndexError: no such group"
### Description

When configuring Arithmatex to disable the `$` syntax for inline mathematics with this configuration:
```yaml
# ...
  - pymdownx.arithmatex:
      # ...
      inline_syntax: [round]
```
Any markdown which contains `\( \)` (which is the`round` syntax left enabled) will fail to render with this exception:

```
Traceback (most recent call last):
  ...
  File ".../site-packages/markdown/core.py", line 268, in convert
    newRoot = treeprocessor.run(root)
  File ".../site-packages/markdown/treeprocessors.py", line 371, in run
    self.__handleInline(text), child
  File ".../site-packages/markdown/treeprocessors.py", line 131, in __handleInline
    data, matched, startIndex = self.__applyPattern(
  File ".../site-packages/markdown/treeprocessors.py", line 272, in __applyPattern
    node, start, end = pattern.handleMatch(match, data)
  File ".../site-packages/pymdownx/arithmatex.py", line 254, in handleMatch
    escapes = m.group(4)
IndexError: no such group
```

All of the following settings for `inline_syntax` still work:
```yaml
[round, dollar] # this is the default anyway
[dollar]
[]
```
So it's just this combination of round only that breaks.

This issue also appears to be unrelated to any of the other Arithmatex options (e.g. `smart_dollar: false` does not fix it)

### Minimal Reproduction

1. Configure pymdown-extensions to enable Arithmatex and set `inline_syntax: [round]`
2. Try to render the markdown `\( 1 + 2 = 3 \)`
3. Observe the error

### Version(s) & System Info

- Operating System: Arch Linux
- Python Version: 3.10.1
- Package Version: 9.1

Discussion:
facelessuser: @gir-bot lgtm

Patch:
diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md
index 2b321766..7ccc839c 100644
--- a/docs/src/markdown/about/changelog.md
+++ b/docs/src/markdown/about/changelog.md
@@ -1,5 +1,10 @@
 # Changelog
 
+## 9.2
+
+- **FIX**: Arithmatex: fix issue where if you limit the inline or block syntax to specific input types access to certain
+  matched groups could cause an error.
+
 ## 9.1
 
 - **NEW**: Highlight: If `linenums` is enabled globally via the `highlight` extension, and a code block specifies a line
diff --git a/pymdownx/__meta__.py b/pymdownx/__meta__.py
index 570640cb..42a5fd26 100644
--- a/pymdownx/__meta__.py
+++ b/pymdownx/__meta__.py
@@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
     return Version(major, minor, micro, release, pre, post, dev)
 
 
-__version_info__ = Version(9, 1, 0, "final")
+__version_info__ = Version(9, 2, 0, "final")
 __version__ = __version_info__._get_canonical()
diff --git a/pymdownx/arithmatex.py b/pymdownx/arithmatex.py
index be1b8338..dbcb0ce5 100644
--- a/pymdownx/arithmatex.py
+++ b/pymdownx/arithmatex.py
@@ -249,16 +249,17 @@ class InlineArithmatexPattern(InlineProcessor):
         """Handle notations and switch them to something that will be more detectable in HTML."""
 
         # Handle escapes
-        escapes = m.group(1)
-        if not escapes:
-            escapes = m.group(4)
+        groups = m.groups()
+        escapes = groups[0]
+        if not escapes and len(groups) > 3:
+            escapes = groups[3]
         if escapes:
             return escapes.replace('\\\\', self.ESCAPED_BSLASH), m.start(0), m.end(0)
 
         # Handle Tex
-        math = m.group(3)
-        if not math:
-            math = m.group(6)
+        math = groups[2]
+        if not math and len(groups) > 3:
+            math = groups[5]
 
         if self.generic:
             return _inline_generic_format(math, wrap=self.wrap, tag=self.inline_tag), m.start(0), m.end(0)
@@ -316,11 +317,12 @@ class BlockArithmatexProcessor(BlockProcessor):
 
         blocks.pop(0)
 
-        math = self.match.group('math')
+        groups = self.match.groupdict()
+        math = groups.get('math', '')
         if not math:
-            math = self.match.group('math2')
+            math = groups.get('math2', '')
         if not math:
-            math = self.match.group('math3')
+            math = groups.get('math3', '')
 
         if self.generic:
             self.generic_output(parent, math)


Test patch:
diff --git a/tests/test_extensions/test_arithmatex.py b/tests/test_extensions/test_arithmatex.py
index 4539bbde..01203f70 100644
--- a/tests/test_extensions/test_arithmatex.py
+++ b/tests/test_extensions/test_arithmatex.py
@@ -2,6 +2,45 @@
 from .. import util
 
 
+class TestArithmatexLimit(util.MdCase):
+    """Test limiting Arithmatex inline and block inputs."""
+
+    extension = [
+        'pymdownx.arithmatex'
+    ]
+    extension_configs = {'pymdownx.arithmatex': {'inline_syntax': ['round'], 'block_syntax': ['square']}}
+
+    def test_round_only(self):
+        """Test round only."""
+
+        self.check_markdown(
+            "\\(1 + 2 + 3\\)",
+            """<p><span class="arithmatex"><span class="MathJax_Preview">1 + 2 + 3</span><script type="math/tex">1 + 2 + 3</script></span></p>"""  # noqa: E501
+        )
+
+    def test_square_only(self):
+        """Test square only."""
+
+        self.check_markdown(
+            r"""
+            \[
+            1 + 2 + 3
+            \]
+            """,
+            r"""
+            <div class="arithmatex">
+            <div class="MathJax_Preview">
+            1 + 2 + 3
+            </div>
+            <script type="math/tex; mode=display">
+            1 + 2 + 3
+            </script>
+            </div>
+            """,
+            True
+        )
+
+
 class TestArithmatexBlockEscapes(util.MdCase):
     """Test escaping cases for Arithmatex blocks."""