Warning: This Code is a total mess! I am sorry for that. But it has 100% test coverage so whenever someone introduces a new hack to get it working, we can be confident that nothing unexpectedly breaks.
All features were developed for compatibility with the modernthesis template.
# yarn
yarn global add @adrianjost/md2tex
# or npm
npm i -g @adrianjost/md2texmd2tex "pathToSrcMdFile" "pathToTargetTexFile"- The
pathToSrcMdFiledefault to./in.md. - The
pathToTargetTexFiledefault to./out.tex.
If you provide a directory path instead of a file for both paths, all .md files will get converted to the output directory. The Filestructure will remain the same.
# yarn
yarn add -D @adrianjost/md2tex
# or npm
npm i -D @adrianjost/md2teximport md2tex from "@adrianjost/md2tex";
// or
// const { convert: md2tex } = require("@adrianjost/md2tex")
const md = `# Hello World`;
const tex = md2tex(md);
console.log(tex);You can use a codeblock with the language latex to write latex code directly in your markdown files. This Code is getting directly copied into the output without any further conversion.
Input:
# H1
## H2
### H3
#### H4
##### H5
###### H6Output:
%************************************************
\chapter{H1}
\label{ch:0-h1}
%************************************************
\hypertarget{1-h2}{
\section{H2}\label{1-h2}}
\hypertarget{2-h3}{
\subsection{H3}\label{2-h3}}
\hypertarget{3-h4}{
\subsubsection{H4}\label{3-h4}}
\hypertarget{4-h5}{
\paragraph{H5}\label{4-h5}}
\hypertarget{5-h6}{
\subparagraph{H6}\label{5-h6}}Input:
**bold** or **bold**
_italic_ or _italic_
`inline code`Output:
\textbf{bold} or \textbf{bold} \\
\textit{italic} or \textit{italic} \\
\colorbox{gray-light!}{\texttt{inline code}}Links get converted to footnotes or BibLatex Source References
Input:
[descrition](footnote)
[source](`reference`)Output:
description\\footnote{footnote}
source\\cite{reference}Input:
Output:
\begin{figure}[H]
\centering
\includegraphics[width=\textwidth]{path}
\caption[description]{description}
\label{fig:description}
\end{figure}🌟 Please note the special syntax for captions.
Input:
```js [some caption]
console.log("Hi");
```Output:
\begin{listing}[H]
\caption{some caption}
\label{lst:some caption}
\begin{minted}{js}
console.log("Hi");
\end{minted}
\end{listing}Input:
- list item 1
- indentation 1
- list item 2
1. first
2. secondOutput:
\begin{itemize}
\item list item 1
\begin{itemize}
\item indentation 1
\end{itemize}
\item list item 2
\end{itemize}
\begin{enumerate}
\item first
\item second
\end{enumerate}- Currently, this code can't convert tables
- It is also not possible to use inline styles in headlines like
# _italic_ headline - Not all characters get escaped correctly. It's not working inside headlines and normal text without any formatting.
You wan't to contribute? Feel free to do so!
If you have found a bug, just add a snapshot test to the tests located at __tests__/md2tex.test.js and open a pull request.