tomduck / pandoc-theoremnos

A pandoc filter for numbering theorems and theorem references.
GNU General Public License v3.0
9 stars 5 forks source link

TypeError: 'NoneType' object is not subscriptable #5

Open alanzchen opened 3 years ago

alanzchen commented 3 years ago

Got the following error when running:

pandoc -f markdown+smart+fenced_divs --lua-filter=texclass.lua --standalone -F pandoc-theoremnos -F pandoc-crossref --citeproc --number-sections --output=output/test.pdf test.md
Traceback (most recent call last):
  File "/usr/local/bin/pandoc-theoremnos", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/pandoc_theoremnos.py", line 488, in main
    altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
  File "/usr/local/lib/python3.8/dist-packages/pandoc_theoremnos.py", line 488, in <lambda>
    altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
  File "/usr/local/lib/python3.8/dist-packages/pandocfilters.py", line 110, in walk
    res = action(item['t'],
  File "/usr/local/lib/python3.8/dist-packages/pandocxnos/core.py", line 856, in process_refs
    _process_refs(value[-5], pattern, labels)
  File "/usr/local/lib/python3.8/dist-packages/pandocxnos/core.py", line 92, in wrapper
    ret = func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pandocxnos/core.py", line 758, in _process_refs
    if v['t'] == 'Cite' and len(v['c']) == 2:
TypeError: 'NoneType' object is not subscriptable

re.compile('(asum|prop|lemma):[\\w/-]*')
Error running filter pandoc-theoremnos:
Filter returned error status 1

My example markdown is as follows:

---
title: "ABC"
author: "XYZ"
date: \today
geometry: margin=1in
fontsize: 12pt
fontfamily: times
link-citations: true
abstract: "Example."

header-includes:
    - \usepackage{setspace}
    - \doublespacing
    - \usepackage{floatpag}
    - \usepackage{cleveref}
    - \usepackage[utf8]{inputenc}
    - \floatpagestyle{empty}
    - \usepackage[small,compact]{titlesec}
theoremnos-cleveref: True
theoremnos-names:
    - id: asum
      name: Assumption
    - id: prop
      name: Proposition
    - id: lemma
      name: Lemma
---

a   b   c
--- --- ---
1   2   3
4   5   6

: Caption {#tbl:label}

[My Theorem]{#lemma:id}
: This is my theorem.

[123]{#lemma:n-derivative}
: In equilibrium, $n^*$ can be expressed as:

$$
n^*=\frac{b-\frac{4 (\beta  D_H+(1-\beta)D_L)^2}{(\beta D_H^2+(1-\beta)D_L^2)+4/q}}{2 t}
$$

@lemma:n-derivative

@tbl:label

@lemma:id

The problem is with the table reference. That seems to be the one that is conflicting with this filter. Removing the table will resolve the issue, but it is currently the only way to reference a table AFAIK: http://lierdakil.github.io/pandoc-crossref/#table-labels

alanzchen commented 3 years ago

Another test markdown that fails:

---
theoremnos-cleveref: True
theoremnos-names:
    - id: asum
      name: Assumption
    - id: prop
      name: Proposition
    - id: lemma
      name: Lemma
---

@tbl:terms

| A                 | B        | C                                                  |
| ---------------------- | ------------- | ------------------------------------------------------------ |
| D                    | $(0,\infty)$  | F                       |

Table: Terminology Table {#tbl:terms}

@tbl:terms
pandoc -f markdown+smart+fenced_divs --standalone -F pandoc-theoremnos -F pandoc-crossref --citeproc --number-sections --output=test.pdf test.md
alanzchen commented 3 years ago

Ahhh, never mind, just read the fine print that the latest pandoc is not supported.