Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LaTeX Subfiles Support #3530

Closed
schrieveslaach opened this issue Mar 24, 2017 · 2 comments · Fixed by #3532
Closed

Add LaTeX Subfiles Support #3530

schrieveslaach opened this issue Mar 24, 2017 · 2 comments · Fixed by #3532

Comments

@schrieveslaach
Copy link
Contributor

The latex subfiles package provides multi-file projects. Take following files as an example

main.tex:

\documentclass[a4paper,11pt]{article}
\usepackage{subfiles}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\title{Multi-File Project Support for Pandoc}
\author{schrieveslaach}

\begin{document}

\maketitle
\tableofcontents

\begin{abstract}
I want to add subfiles support to pandoc
\end{abstract}

\subfile{f1}
\subfile{f2}

\end{document}

f1.tex:

\documentclass[main.tex]{subfiles}
\begin{document}

\section{AAAAA}

AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA AAAAA 

\end{document}

f2.tex:

\documentclass[main.tex]{subfiles}
\begin{document}

\section{BBBBB}

BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB 

\end{document}

When I convert main.tex with pandoc into an ODT it just contains the heading and the author. I'm using following command: pandoc -f latex -t odt main.tex -o Main.odt

bildschirmfoto von 2017-03-24 14-18-32

I do have a patch which handles the content correctly (see diff and image below). According to the contribution guide I need to add tests (Everything related to that change should be included (including tests and documentation)). However, I'm not an haskell expert and I have no idea to write theses test.

Can you help me to provide a proper pull request?

diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index ae441a38..9c028faa 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -1008,6 +1008,7 @@ include = do
               char '\\'
               name <- try (string "include")
                   <|> try (string "input")
+                  <|> try (string "subfile")
                   <|> string "usepackage"
               -- skip options
               skipMany $ try $ char '[' *> manyTill anyChar (char ']')

bildschirmfoto von 2017-03-24 14-20-55

@jgm
Copy link
Owner

jgm commented Mar 24, 2017

You can do this without writing Haskell. Easiest way to add a test would be to add a file 3530.md in tests/command. You'd use pandoc -f latex -t native and provide a short latex snippet (as minimal as possible) including some subfile commands. You'd also need to add short tex files for these in the same directory. (Because the working directory is test when tests are run, you'll need \subfile{command/foo} and the like.) Be sure to add these tex files to the extra-source-files section of pandoc.cabal or they won't be included in the dist tarball.

You should also have a test that does pandoc -flatex+raw_tex -t native. If, as I suspect, this has the bad result that the documentclass and begin/end document commands are included as raw tex, then additional code may need to be written to extract the part of the included file that is between begin/end{document}.

@schrieveslaach
Copy link
Contributor Author

@jgm, thanks for your help. 😊 I provided a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants