Skip to content

Commit

Permalink
Get pandoc-crossref compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Jan 22, 2024
1 parent 7bf5fe9 commit 0379af3
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 13 deletions.
18 changes: 17 additions & 1 deletion pandoc_numbering.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import unicodedata
from functools import partial
from textwrap import dedent

from panflute import (
BlockQuote,
Expand Down Expand Up @@ -1520,7 +1521,22 @@ def finalize(doc):
doc.metadata["header-includes"] = MetaList(doc.metadata["header-includes"])

doc.metadata["header-includes"].append(
MetaInlines(RawInline(r"\usepackage{tocloft}", "tex"))
MetaInlines(
RawInline(
dedent(
r"""
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
"""
),
"tex",
)
)
)
doc.metadata["header-includes"].append(
MetaInlines(RawInline(r"\usepackage{etoolbox}", "tex"))
Expand Down
42 changes: 38 additions & 4 deletions tests/test_listings_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,16 @@ def test_listing_latex(self):
r"""
---
header-includes:
- "`\\usepackage{tocloft}`{=tex}"
- |
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
- "`\\usepackage{etoolbox}`{=tex}"
- "`\\newlistof{exercise}{exercise}{List of exercises}\\renewcommand{\\cftexercisetitlefont}{\\cfttoctitlefont}\\setlength{\\cftexercisenumwidth}{\\cftfignumwidth}\\setlength{\\cftexerciseindent}{\\cftfigindent}`{=tex}"
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\listofexercise\\oldmainmatter}}{}`{=tex}"
Expand All @@ -178,7 +187,15 @@ def test_listing_latex(self):
listing-title: List of exercises
---
`\usepackage{tocloft}`{=tex}
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
`\usepackage{etoolbox}`{=tex}
Expand Down Expand Up @@ -260,7 +277,16 @@ def test_listing_latex_format(self):
r"""
---
header-includes:
- "`\\usepackage{tocloft}`{=tex}"
- |
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
- "`\\usepackage{etoolbox}`{=tex}"
- "`\\newlistof{exercise}{exercise}{List of exercises}\\renewcommand{\\cftexercisetitlefont}{\\cfttoctitlefont}\\setlength{\\cftexercisenumwidth}{\\cftfignumwidth}\\setlength{\\cftexerciseindent}{\\cftfigindent}`{=tex}"
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\listofexercise\\oldmainmatter}}{}`{=tex}"
Expand All @@ -276,7 +302,15 @@ def test_listing_latex_format(self):
toccolor: blue
---
`\usepackage{tocloft}`{=tex}
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
`\usepackage{etoolbox}`{=tex}
Expand Down
21 changes: 19 additions & 2 deletions tests/test_para.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,29 @@ def test_numbering_latex(self):
r"""
---
header-includes:
- "`\\usepackage{tocloft}`{=tex}"
- |
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
- "`\\usepackage{etoolbox}`{=tex}"
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\oldmainmatter}}{}`{=tex}"
---
`\usepackage{tocloft}`{=tex}
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
`\usepackage{etoolbox}`{=tex}
Expand Down
21 changes: 19 additions & 2 deletions tests/test_referencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,29 @@ def test_referencing_latex(self):
r"""
---
header-includes:
- "`\\usepackage{tocloft}`{=tex}"
- |
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
- "`\\usepackage{etoolbox}`{=tex}"
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\oldmainmatter}}{}`{=tex}"
---
`\usepackage{tocloft}`{=tex}
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
`\usepackage{etoolbox}`{=tex}
Expand Down
42 changes: 38 additions & 4 deletions tests/test_referencing_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ def test_referencing_link_latex(self):
r"""
---
header-includes:
- "`\\usepackage{tocloft}`{=tex}"
- |
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
- "`\\usepackage{etoolbox}`{=tex}"
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\oldmainmatter}}{}`{=tex}"
pandoc-numbering:
Expand All @@ -94,7 +103,15 @@ def test_referencing_link_latex(self):
format-link-title: "**%D %d %T %t %g %s %n %p**"
---
`\usepackage{tocloft}`{=tex}
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
`\usepackage{etoolbox}`{=tex}
Expand Down Expand Up @@ -192,7 +209,16 @@ def test_referencing_caption_latex(self):
r"""
---
header-includes:
- "`\\usepackage{tocloft}`{=tex}"
- |
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
- "`\\usepackage{etoolbox}`{=tex}"
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\oldmainmatter}}{}`{=tex}"
pandoc-numbering:
Expand All @@ -204,7 +230,15 @@ def test_referencing_caption_latex(self):
format-caption-title: "%D %d %T %t %g %s %n %c %p"
---
`\usepackage{tocloft}`{=tex}
`
\makeatletter
\@ifpackageloaded{subfig}{
\usepackage[subfigure]{tocloft}
}{
\usepackage{tocloft}
}
\makeatother
`{=tex}
`\usepackage{etoolbox}`{=tex}
Expand Down

0 comments on commit 0379af3

Please sign in to comment.