You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to convert a latex file into a markdown file. The original file contains definitions and theorems like:
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\usepackage{babel}
\usepackage{verbatim}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\theoremstyle{definition}
\newtheorem{prop}{\protect\propositionname}
\theoremstyle{definition}
\newtheorem{defn}{\protect\definitionname}
\theoremstyle{definition}
\newtheorem{example}{\protect\examplename}
\theoremstyle{definition}
\newtheorem{rem}{\protect\remarkname}
\providecommand{\definitionname}{Definition}
\providecommand{\examplename}{Example}
\providecommand{\propositionname}{Proposition}
\providecommand{\remarkname}{Remark}
\begin{document}
\section{Section 1}
\begin{prop}
\label{p1}Name of the proposition
This is a proposition
\end{prop}
\begin{defn}
\label{d1}Name of the definition
This is a definition.
\end{defn}
\end{document}
which gives the pdf output as
by using the following pandocfilters code
from pandocfilters import toJSONFilter, RawBlock, Div, stringify, RawInline
def theorems(key, value, format, meta):
if key == 'Div':
[[ident, classes, kvs], contents] = value
if "prop" in classes:
if ident == "":
label = ""
else:
label = ':label:' + ident
title = contents[0:1]
return([RawBlock('markdown', ':::{note}')] + title + [RawBlock('markdown', label)] + [RawBlock('markdown', ':icon: false')]
+ [RawBlock('markdown', ':class: dropdown')] + contents[1:] + [RawBlock('markdown', ':::')])
elif "defn" in classes:
if ident == "":
label = ""
else:
label = ':label:' + ident
title = contents[0:1]
return([RawBlock('markdown', ':::{hint}')] + title + [RawBlock('markdown', label)] + [RawBlock('markdown', ':icon: false')]
+ [RawBlock('markdown', ':class: dropdown')] + contents[1:] + [RawBlock('markdown', ':::')])
else:
return
if __name__ == "__main__":
toJSONFilter(theorems)
The output markdown file is of the form
# Section 1
:::{note}
** 1**. Name of the proposition
:label:p1
:icon: false
:class: dropdown
This is a proposition
:::
:::{hint}
** 1**. Name of the definition
:label:d1
:icon: false
:class: dropdown
This is a definition.
:::
in which the proposition and the definition will be put into 'admonition' blocks. But the correct form I want to achieve is
# Section 1
:::{note} ** 1**. Name of the proposition
:label:p1
:icon: false
:class: dropdown
This is a proposition
:::
:::{hint} ** 1**. Name of the definition
:label:d1
:icon: false
:class: dropdown
This is a definition.
:::
In addition, I do not want the numbering to be in 'strong', which means my desired outcome would be like
# Section 1
:::{note} 1. Name of the proposition
:label:p1
:icon: false
:class: dropdown
This is a proposition
:::
:::{hint} 1. Name of the definition
:label:d1
:icon: false
:class: dropdown
This is a definition.
:::
I read the documentation and learned that the AST of part of the proposition is in the form of
, Div
( "p1" , [ "prop" ] , [] )
[ Para
[ Strong [ Space , Str "1" ]
, Str "."
, Space
, Space
, Str "Name"
, Space
, Str "of"
, Space
, Str "the"
, Space
, Str "proposition"
]
So I need to extract the first paragraph of the 'Div', remove the 'strong' formatting of the number, get rid of the space in front of it, and place this paragraph in the same line with the beginning of the admonition block :::{note}.
I just started to learn to use pandoc filter, and I assume that there must be many mistakes in my method of achieving the goal. My question is: How can I extract a child element from its parent (in the present case, the strong-formatted string '1' from the paragraph) and manipulate it?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I want to convert a latex file into a markdown file. The original file contains definitions and theorems like:
which gives the pdf output as
by using the following pandocfilters code
The output markdown file is of the form
in which the proposition and the definition will be put into 'admonition' blocks. But the correct form I want to achieve is
In addition, I do not want the numbering to be in 'strong', which means my desired outcome would be like
I read the documentation and learned that the AST of part of the proposition is in the form of
So I need to extract the first paragraph of the 'Div', remove the 'strong' formatting of the number, get rid of the space in front of it, and place this paragraph in the same line with the beginning of the admonition block
:::{note}
.I just started to learn to use pandoc filter, and I assume that there must be many mistakes in my method of achieving the goal. My question is: How can I extract a child element from its parent (in the present case, the strong-formatted string '1' from the paragraph) and manipulate it?
Could anybody please show me how to do this?
Beta Was this translation helpful? Give feedback.
All reactions