Markdown is a great way to write a small article, and sometimes a rather lengthy text, with simple formatting in the form of italics and thick type. Also Markdown is not bad for writing articles with the inclusion of source code. But sometimes you want without loss, dancing with a tambourine to overtake it in a normal, well-designed PDF file, and so that there were no problems with converting, such as I had, you cannot write in Russian in the comments of the source code, too long lines are not transferred, other minor problems are cut off. The manual will allow you to quickly set up the md2pdf converter, without really understanding how it works. The script for a more or less automatic installation is below in the appropriate section.
My example of a TeX template for conversion uses the PSCyr font package, which includes support for Microsoft fonts, namely Times New Roman . Such were the requirements for the diploma according to GOST. If you can, you can modify the template to fit your needs. In my own instructions, you will first have to blink with the PSCyr setting in TexLive. The configuration is done in the Linux Mint Mate distribution, for other distributions you may have to google the standard TexLive folders for your system.
Of course, you can install only the right parts of this package. But personally, I was frankly too lazy to look for the minimum necessary working installation. For everything to work, install the entire TexLive package. It is called texlive-full and weighs slightly more than 2 gigabytes, keep this fact in mind. Execute the command:
user@hostname:~$ sudo apt install texlive-full -y
After a long enough installation, you can proceed to the next item.
Pandoc is a Linux package that allows you to convert some text formats to others. There are many interesting features that you can get acquainted yourself on the Internet. We are only interested in the ability to convert the markdown file to PDF. Check whether Pandoc is installed and if not, then install it. For example:
user@hostname:~$ dpkg -s pandoc
If the output says it is not installed - install:
user@hostname:~$ sudo apt install pandoc -y
First you need to download PSCyr. So far, it is available via this link , if at the time of reading the article it is for some reason not available, do not despair, it is easy to find it along with the installation instructions, typing something like “Installing PsCyr texlive” in Google. If it is available, then it is easier for you to download and we will assume that you unpacked the archive into your home folder and thus the path to the folder contained in the archive looks like ~ / PSCyr . Then we go to the Terminal and consistently execute the commands:
user@hostname:~$ cd user@hostname:~$ mkdir ./PSCyr/fonts/map ./PSCyr/fonts/enc user@hostname:~$ cp ./PSCyr/dvips/pscyr/*.map ./PSCyr/fonts/map/ user@hostname:~$ cp ./PSCyr/dvips/pscyr/*.enc ./PSCyr/fonts/enc/ user@hostname:~$ echo "fadr6t AdvertisementPSCyr \"T2AEncoding ReEncodeFont\"" > ./PSCyr/fonts/map/pscyr.map
Next, find out where the local texmf directory is located. Execute the command:
user@hostname:~$ kpsewhich -expand-var='$TEXMFLOCAL'
Most likely this directory is / usr / local / share / texmf / , and then we execute:
user@hostname:~$ sudo cp -R ./PSCyr/* /usr/local/share/texmf/
Well, or you can not bother and execute a command that will copy into the texmf folder wherever it is:
user@hostname:~$ sudo cp -R ./PSCyr/* $(kpsewhich -expand-var='$TEXMFLOCAL')
PSCyr fonts installed, plug into TexLive:
user@hostname:~$ sudo texhash user@hostname:~$ updmap --enable Map=pscyr.map user@hostname:~$ sudo mktexlsr
I will not describe how exactly this template is set up, and just give it under the spoiler without much explanation. Suffice it to say that it is configured well, at least how it handles texts with a lot of source code. If you are not satisfied with the size of indents, line spacing, lack of numbering of sections and subsections, then in my opinion it is quite easy to google the question on the Internet "how to do it in Latex ..." and then your need. If it is completely incomprehensible, write in the comments, I will try to penetrate into your own settings 4 years ago in order to describe which line of the template is responsible for what. In the meantime, I will sign as I did on my PC, and you are free to repeat or modify it for yourself.
Create a template.tex file in the / usr / share / texlive / directory:
user@hostname:~$ sudo touch /usr/share/texlive/template.tex
We ask him to read:
user@hostname:~$ sudo chmod 444 /usr/share/texlive/template.tex
open under the root and insert the contents hidden under the spoiler below:
user@hostname:~$ sudo nano /usr/share/texlive/template.tex
\documentclass[oneside,final,14pt]{extreport} \usepackage{extsizes} \usepackage{pscyr} \renewcommand{\rmdefault}{ftm} \usepackage[T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{mathtext} \usepackage{multirow} \usepackage{listings} \usepackage{ucs} \usepackage{hhline} \usepackage{tabularx} \usepackage{booktabs} \usepackage{longtable} \usepackage{titlesec} \usepackage{hyperref} \usepackage{graphicx} \usepackage{setspace} \usepackage[center,it,labelsep=period]{caption} \usepackage[english,russian,ukrainian]{babel} \usepackage{vmargin} \newcommand{\specialcell}[2][c]{% \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}} \setpapersize{A4} \setmarginsrb {1cm}{1cm}{1cm}{1cm}{0pt}{0mm}{0pt}{13mm} \usepackage{indentfirst} \setlength\parindent{1cm} \renewcommand{\baselinestretch}{1} \renewcommand\thechapter{} \renewcommand\thesection{} \renewcommand\thesubsection{} \renewcommand\thesubsubsection{} \titleformat {\chapter} % command {\bfseries\normalsize\centering} % format {\thechapter} % label {0.5ex} % sep { \centering } [ \vspace{-1.5ex} ] % after-code \titleformat {\section} [block] {\normalfont\bfseries} {\thesection}{0.5em}{} \sloppy \let\oldenumerate\enumerate \renewcommand{\enumerate}{ \oldenumerate \setlength{\itemsep}{1pt} \setlength{\parskip}{0pt} \setlength{\parsep}{0pt} } \let\olditemize\itemize \renewcommand{\itemize}{ \olditemize \setlength{\itemsep}{1pt} \setlength{\parskip}{0pt} \setlength{\parsep}{0pt} } \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \titlespacing{\subsubsection}{\parindent}{3mm}{3mm} \titlespacing{\subsection}{\parindent}{3mm}{3mm} \usepackage{color} \lstset{ basicstyle=\footnotesize\ttfamily, inputencoding=utf8, extendedchars=\true, showspaces=false, keepspaces=true showstringspaces=false, showtabs=false, tabsize=4, captionpos=b, breaklines=true, breakatwhitespace=true, breakautoindent=true, linewidth=\textwidth } \begin{document} $if(title)$ \maketitle $endif$ $if(abstract)$ \begin{abstract} $abstract$ \end{abstract} $endif$ $for(include-before)$ $include-before$ $endfor$ $if(toc)$ { $if(colorlinks)$ \hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$black$endif$} $endif$ \setcounter{tocdepth}{$toc-depth$} \tableofcontents } $endif$ $if(lot)$ \listoftables $endif$ $if(lof)$ \listoffigures $endif$ $body$ $if(natbib)$ $if(bibliography)$ $if(biblio-title)$ $if(book-class)$ \renewcommand\bibname{$biblio-title$} $else$ \renewcommand\refname{$biblio-title$} $endif$ $endif$ \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$} $endif$ $endif$ $if(biblatex)$ \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ $endif$ $for(include-after)$ $include-after$ $endfor$ \end{document}
Save the file /usr/share/texlive/template.tex and write a script that will convert the Makrdown file to PDF, creating a file with the name Markdown file with the prefix .pdf in the same folder, that is, after converting filename.md, filename will appear in the folder . md.pdf . The script is called md2pdf and put along the path / usr / bin . Run the following commands in sequence:
user@hostname:~$ cd user@hostname:~$ touch md2pdf user@hostname:~$ echo "#!/bin/bash" > md2pdf user@hostname:~$ echo "pandoc --output=$1.pdf --from=markdown_github --latex-engine=pdflatex --listings --template=/usr/share/texlive/template.tex $1" >> md2pdf user@hostname:~$ sudo cp md2pdf /usr/bin/ user@hostname:~$ sudo chmod 111 /usr/bin/md2pdf
The 4th line actually contains the conversion command. Notice the --from = markdown_github . GitHub version of Markdown is backward compatible with the original Markdown, so if you write your text on it, you can not worry. If your MD file is written in a specific Markdown dialect, then read the manual by Pandoc ( man pandoc
), make sure that your implementation is supported by it, and correct / usr / bin / md2pdf if necessary.
If you don’t really want to customize anything at all, and you have a Ubuntu-like distribution, you can try to create a script with the content hidden under the spoiler, and most likely everything will be installed by itself, only the TeX template laid out above the spoiler above, copy where necessary yourself. Open Terminal and execute:
user@hostname:~$ cd user@hostname:~$ touch installmd2pdf.sh
Further fill it with such contents:
#!/bin/bash cd /tmp sudo apt install texlive-full pandoc -y wget http://blog.harrix.org/wp-content/uploads/2013/02/PSCyr.zip unzip -qq PSCyr.zip cd mkdir ./PSCyr/fonts/map ./PSCyr/fonts/enc cp ./PSCyr/dvips/pscyr/*.map ./PSCyr/fonts/map/ cp ./PSCyr/dvips/pscyr/*.enc ./PSCyr/fonts/enc/ echo "fadr6t AdvertisementPSCyr \"T2AEncoding ReEncodeFont\"" > ./PSCyr/fonts/map/pscyr.map sudo cp -R ./PSCyr/* $(kpsewhich -expand-var='$TEXMFLOCAL') sudo texhash updmap --enable Map=pscyr.map sudo mktexlsr sudo touch /usr/share/texlive/template.tex touch md2pdf echo "#!/bin/bash" > md2pdf echo "pandoc --output=$1.pdf --from=markdown_github --latex-engine=pdflatex --listings --template=/usr/share/texlive/template.tex $1" >> md2pdf sudo cp md2pdf /usr/bin/ sudo chmod 111 /usr/bin/md2pdf
Run it with the command:
user@hostname:~$ sudo bash $HOME/installmd2pdf.sh
Do not forget that /usr/share/texlive/template.tex must be filled with the contents specified in the " LaTeX template for md2pdf conversion " section .
Just open the folder with the Markdown file ( some_file.md ) in the Terminal, and execute the command:
user@hostname:~$ md2pdf some_file.md
As a result, the file will appear some_file.md.pdf file.
Based on the described method, you can build any style of PDF files, you can also convert other formats instead of md, any supported by Pandoc. I dare to hope that once this instruction comes in handy for 3 and a half people.
Source: https://habr.com/ru/post/444262/
All Articles