CLRafaelR / pangloss

DEPRECATED: Interlinear glosses for pandoc (Use: pandoc-ling by Michael Cysouw)
MIT License
0 stars 1 forks source link

Pangloss overkills the markdown-native numbered example lists #1

Closed CLRafaelR closed 4 years ago

CLRafaelR commented 4 years ago

@kisiyamat

Main issue

I'm writing an (R)markdown file with some interlinear gloss and trying to produce a PDF. In the (R)markdown file, there is also some examples coded with the markdown-native numbered example lists, as shown below:

(@vanish2) I vanish in the tex file! Please save me!

However, pangloss overkills this numbered example lists and the notation above (i.e. (@vanish2)) would not be rendered into a LaTeX and PDF file.

To prevent this malfunction, it is possible to add \ to the second and third line of the gloss environment. However, this leaves an undesirable pair of brackets in the third line in the PDF file.

(@gloss-unnecessary) This does not require any gloss.
    \ 
    \ \           

I suspect that l.21 if text[:4] == '@ex:': in pangloss.py has something to do with the issue, since from this line pangloss modifies the md file.

Do you have any suggestion to avoid this issue?

MWE

---
title: Interlinear Glossing
author: CLRR
documentclass: article
classoption: leqno,fleqn
citeproc: no
output:
  bookdown::pdf_document2:
    latex_engine: xelatex
    toc: FALSE
    keep_tex: true
    pandoc_args:
      - --filter
      - pangloss
    includes:
      in_header: header.tex
---

```{cat, engine.opts=list(file = 'header.tex')}
\makeatletter
\def\new@fontshape{}
\makeatother
\let\mathexp=\exp % save the math definition of \exp
\usepackage{gb4e}\noautomath
\let\gbexp=\exp % save the gb4e definition of \exp
\DeclareRobustCommand{\exp}{\ifmmode\mathexp\else\expandafter\gbexp\fi}
```

# Main issue

The `pangloss` filter enables us to write an interlinear glossing so easily in a markdown notation as exemplified bellow,
producing in (@ex-japanese).

```
(@ex-japanese) Kore ni-wa gloss ga irimasu.
    This DAT-TOP gloss NOM necessary
    This needs a gloss.
```

(@ex-japanese) Kore ni-wa gloss ga irimasu.
    This DAT-TOP gloss NOM necessary
    This needs a gloss.

However, the filter overkills the markdown-native [numbered example lists](https://pandoc.org/MANUAL.html#numbered-example-lists)
(https://pandoc.org/MANUAL.html#numbered-example-lists). Therefore, (@vanish2) is invisible in the output PDF. 
(@vanish2) would have been rendered from the follwing notation.

```
(@vanish2) I vanish in the tex file! Please save me!
```

To prevent this malfunction, it is possible to add `\ ` to the second and third line of the gloss environment.
However, this leaves an undesirable pair of brackets in the third line as shown below.

```
(@gloss-unnecessary) This does not require any gloss.
    \ 
    \ \           
```

(@gloss-unnecessary) This does not require any gloss.
    \ 
    \ \           

(@vanish2) I vanish in the tex file! Please save me!

I suspect that l.21 `if text[:4] == '@ex:':` in [`pangloss.py`](https://github.com/daemanos/pangloss/blob/master/pangloss/pangloss.py) 
has something to do with the issue, since from this line `pangloss` modifies the md file.

Secondary output (md)

---
title: Interlinear Glossing
author: CLRR
documentclass: article
classoption: leqno,fleqn
citeproc: no
output:
  bookdown::pdf_document2:
    latex_engine: xelatex
    toc: FALSE
    keep_tex: true
    keep_md: true
    pandoc_args:
      - --filter
      - pangloss
    includes:
      in_header: header.tex
---

# Main issue

The `pangloss` filter enables us to write an interlinear glossing so easily in a markdown notation as exemplified bellow,
producing in (@ex-japanese).

```
(@ex-japanese) Kore ni-wa gloss ga irimasu.
    This DAT-TOP gloss NOM necessary
    This needs a gloss.
```

(@ex-japanese) Kore ni-wa gloss ga irimasu.
    This DAT-TOP gloss NOM necessary
    This needs a gloss.

However, the filter overkills the markdown-native [numbered example lists](https://pandoc.org/MANUAL.html#numbered-example-lists)
(https://pandoc.org/MANUAL.html#numbered-example-lists). Therefore, (@vanish2) is invisible in the output PDF. 
(@vanish2) would have been rendered from the follwing notation.

```
(@vanish2) I vanish in the tex file! Please save me!
```

To prevent this malfunction, it is possible to add `\ ` to the second and third line of the gloss environment.
However, this leaves an undesirable pair of brackets in the third line as shown below.

```
(@gloss-unnecessary) This does not require any gloss.
    \ 
    \ \           
```

(@gloss-unnecessary) This does not require any gloss.
    \ 
    \ \           

(@vanish2) I vanish in the tex file! Please save me!

I suspect that l.21 `if text[:4] == '@ex:':` in [`pangloss.py`](https://github.com/daemanos/pangloss/blob/master/pangloss/pangloss.py) 
has something to do with the issue, since from this line `pangloss` modifies the md file.

Output (PDF)

image

Output (LaTeX)

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
  leqno,fleqn]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={Interlinear Glossing},
  pdfauthor={CLRR},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{longtable,booktabs}
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\makeatletter
\def\new@fontshape{}
\makeatother
\let\mathexp=\exp % save the math definition of \exp
\usepackage{gb4e}\noautomath
\let\gbexp=\exp % save the gb4e definition of \exp
\DeclareRobustCommand{\exp}{\ifmmode\mathexp\else\expandafter\gbexp\fi}

\title{Interlinear Glossing}
\author{CLRR}
\date{}

\begin{document}
\maketitle

\hypertarget{main-issue}{%
\section{Main issue}\label{main-issue}}

The \texttt{pangloss} filter enables us to write an interlinear glossing so easily     in a markdown notation as exemplified bellow,
producing in (1).

\begin{verbatim}
(@ex-japanese) Kore ni-wa gloss ga irimasu.
    This DAT-TOP gloss NOM necessary
    This needs a gloss.
\end{verbatim}

\begin{exe}

\ex
\gll Kore ni-wa gloss ga irimasu. \\
This \textsc{dat}-\textsc{top} gloss \textsc{nom} necessary \\
\trans `This needs a gloss.' \\
\end{exe}

However, the filter overkills the markdown-native \href{https://pandoc.org/MANUAL.    html\#numbered-example-lists}{numbered example lists}
(\url{https://pandoc.org/MANUAL.html\#numbered-example-lists}). Therefore, (3) is     invisible in the output PDF.
(3) would have been rendered from the follwing notation.

\begin{verbatim}
(@vanish2) I vanish in the tex file! Please save me!
\end{verbatim}

To prevent this malfunction, it is possible to add \texttt{\textbackslash{}} to     the second and third line of the gloss environment.
However, this leaves an undesirable pair of brackets in the third line as shown below.

\begin{verbatim}
(@gloss-unnecessary) This does not require any gloss.
    \ 
    \ \           
\end{verbatim}

\begin{exe}

\ex
\gll This does not require any gloss. \\
  \\
\trans `  ' \\
\end{exe}

I suspect that l.21 \texttt{if\ text{[}:4{]}\ ==\ \textquotesingle{}    @ex:\textquotesingle{}:} in \href{https://github.com/daemanos/pangloss/blob/master/    pangloss/pangloss.py}{\texttt{pangloss.py}}
has something to do with the issue, since from this line \texttt{pangloss} modifies     the md file.

\end{document}
kishiyamat commented 4 years ago

長いっすね...。YAML部分って再現に必要です?

kishiyamat commented 4 years ago

あぁ再現できました

kishiyamat commented 4 years ago

あぁ、てっとり速い解決策としては tex を埋め込むとかでも良い気がしますが

CLRafaelR commented 4 years ago

@kishiyamat

Inputting raw LaTeX commands on Rmd, as you mentioned, is not desirable for me in two senses: 1. that's what I'm always doing and then we cannot enjoy the easy, readable/writable notation of markdown; 2. the gb4e commands are not rendered when we want to produce HTML file. For these reasons, I want to stick to pangloss' markdown notation here.

CLRafaelR commented 4 years ago

Resolved with #3c6f4f3