# Someone provide a tutorial link for Pandoc txt to tex [closed]

can someone provide a link to either documentation or a tutorial on how to convert txt files to tex files. You will probably have to extrapolate this question since I don't know enough to compose a more precise question. I want to convert some txt files to basic tex files. They are utf8, and I don't want to print them with notepad or a text editor, but rather have LaTeX typeset them.

I'm visualizing that I will need to create a LaTeX template for Pandoc. I have a little experience with LaTeX and know how to create basic documents using the basic classes and the basic commands, but would be lost if I had to create my own package or class. I don't know anything about pandoc except that it's a command line conversion tool that can roughly convert from one filetype to another, with a probably loss of formatting due to differences in features of the filetypes. My txt files have zero formatting syntax coded inside them, it's just unicode characters in utf8 txt files. All of the characters are American Latin types.

Someone please provide a helpful tutorial to pandoc, or documentation, or correct my ignorance as much as possible.

## closed as off-topic by Martin Schröder, Stefan Pinnow, Kurt, user13907, Maarten DhondtDec 5 '16 at 10:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center." – Martin Schröder, Stefan Pinnow, Kurt, Community, Maarten Dhondt
If this question can be reworded to fit the rules in the help center, please edit the question.

• IMHO, questions about pandoc itself are not on-topic, but about produce LaTeX (with or without pandoc) are on-topic. – Fran Dec 8 '16 at 12:32

Given the requirements of the OP, the simplest way is to create the following template (and name it templates.tex)

\documentclass{article}

\usepackage[utf8]{inputenc}

\begin{document}

$body$

\end{document}


Then Pandoc can be called with the following command

pandoc --template=templatex.tex <file.txt> -o <file.tex>


where <file.txt> is the name of the input txt file and <file.tex> is the name of the output to be created by pandoc.

By the way Pandoc documentation for templates is available at http://pandoc.org/MANUAL.html#options-for-wrapper-scripts.

• +1. More intrepid pandoctors might want to modify default.latex to suit their needs, or to get inspired about the possibilities available. – jon Dec 3 '16 at 19:52

Pandoc txt to tex

Sensu stricto it is not as easy as it looks.

Pandoc only write to plain text but does not read plain text, thus is not exactly the right tool, except if you want that plain text will be interpreted as Markdown (that however, very probably is what you really want).

My txt files have zero formatting syntax coded inside them

Probably is not true (for the point of view of pandoc). Probably the text in the converted file will be plagued of LaTeX commands no matter how simple your template will be, except if the text has not other structure that normal paragraphs. But a text with simple headers, or some list, for example:

Heading
-------

Vivamus 12% nunc & nunc, molestie ut, ultricies vel, semper in,
velit. Ut porttitor. Praesent in sapien. Nam rutrum augue a leo.

- First item text
- Second item text
1. First subitem text
2. Second subitem text


...look like plain text, but really have some Markdown syntax that will be converted to LaTeX, so the result with the template of Guido's answer will be:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}

Vivamus 12\% nunc \& nunc, molestie ut, ultricies vel, semper in,
velit. Ut porttitor. Praesent in sapien. Nam rutrum augue a leo.

\begin{itemize}
\tightlist
\item
First itemtext
\item
Second itemtext

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
First itemtext
\item
Second itemtext
\end{enumerate}
\end{itemize}
\end{document}


This could be nice (the PDF look perfect) ...or a major drawback if you want strictly what you asked. Suppose that you do not want sections and list LaTeX syntax, only start editing a LaTeX text without structure. Then you nedd only escaping special characters ( \$ & % # _ { } ~ ^ \) since this produce lost of some text (any text after % will be treated as a comment) or fatal rendering errors, but there are not a pandoc option for this, afaik.

I will need to create a LaTeX template for Pandoc.

In general, no. You do not have to worry about templates. By default is applied a template that work in most cases. So this work also:

pandoc -s <file.txt> -o <file.tex>


However, it could be a good idea have your own template if the default template disturb you in some way (for example, you want a cleaner preamble to star editing the LaTeX file). Also it will be better rename file.txt to file.md(so it can be recognized correctly as markdown text by text editors and you).

But you can also work in plain text (markdown) without pandoc conversions and still produce nice LaTeX PDF prints, just working only with one LaTeX document with this structure:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{markdown}
\begin{document}
\begin{markdown}
\end{markdown}
\end{document}


It must be compiled with lualatex. You can also use pdflatex, but it should be able of access the shell in order to run some Lua code (run texdoc markdown for more info).

Or if you want maintain/edit the original <file.txt> anyway, you can also:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{markdown}
\begin{document}
\markdownInput{<file.txt>}
\end{document}


Finally, in case that you do not want any markdown format (just produce a PDF as seen in the plain text editor) thing are a little more complex. Probably the best could be sanitize some markdown syntax and then import to LyX:

pandoc <file.md> -t plain -o <file.txt> && lyx --import text <file.txt>


And then Ctrl+R to obtain the PDF. If you want to join the lines, afaik there are no command line options in LyX, but it is possible via LyX menu File > Import > Plaint Text, Join Lines ... or without LyX, covert directly to LaTeX with the perl script txt2latex:

pandoc <file.md> -t plain | txt2latex > <file.tex>


In this case the result is simple:

\documentclass{article}
\begin{document}

Vivamus 12\% nunc \& nunc, molestie ut, ultricies vel, semper in, velit. Ut
porttitor. Praesent in sapien. Nam rutrum augue a leo.

-   First item text
-   Second item text
1.  First subitem text
2.  Second subitem text

\end{document}


So lack add manually \usepackage[utf8]{inputenc} in the preample. The godd is that if you do not want join lines at some moment, is enough add \obeylines after \begin{document}

Or, in case that you want just show the text verbatim:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{verbatim}
\end{verbatim}
\end{document}


Or just include the original file:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}
\begin{document}
\verbatiminput{borra.md}
\end{document}


Or simply, change \markdownInput by \markdownRendererInputVerbatim in the example using the markdown package.

• that's right. my txt files truly are plain txt files with zero formatting markup. I've since noticed that when I try to convert a latex file back into a "textile"[sic] using Try Pandoc sample page on the internet, that it actually places some sort of markup into the txt files, like "_" before/after an emphaised word or "*" before/after some bold words. I'm studying how to create my own plain text format. Also, a major annoyance is that insertion of 7 bit quotation quotation marks' ' into my supposedly unicode tex files – user12711 Dec 7 '16 at 3:37
• @user12711 Do not use - t textile ("to textile" option of pandoc) , but -t plain to export to plain text. "Textile" is a markup language. Problably you may want use the program detex to strip TeX commands from a .tex file. – Fran Dec 7 '16 at 4:20
• detex is exactly what I'm looking for to go back and forth between latex and txt. I'm going to be using my pandcoc myText.tex exports within an import statement in a latex master document. I also need the ability to export them back out into a txt file (in case I make corrections within the myText.tex files that I import). The only other thing I want to learn how to get pandoc to do is use export unicode quotation marks rather than the  ` something quoted ' ' ascii characters – user12711 Dec 7 '16 at 20:41