Prélude
Markdown hè una bella manera di scrive un articulu brevi, è qualchì volta assai testu, cù un furmatu corsu simplice è grassu. Markdown hè ancu bonu per scrive articuli cù u codice fonte inclusu. Ma qualchì volta vulete perdicà, ballà cù un tamburinu per superà in un schedariu PDF rigulari, ben furmatu, è cusì chì ùn ci hè micca prublemi durante a cunversione, chì, per esempiu, aghju avutu - ùn pudete micca scrive in russo in i cumenti di u codice surghjente, linee troppu longu ùn sò micca trasferiti, ma tagliate è altri prublemi minori. L'istruzzioni vi permetterà di stallà rapidamente u cunvertitore md2pdf senza veramente capisce cumu funziona. U script per una stallazione più o menu automatica hè quì sottu in a sezione approprita.
U mo mudellu TeX di mostra per a cunversione usa u pacchettu di fonti PSCyr, chì include supportu per i caratteri Microsoft, vale à dì Times novu rumanu. Ci era tali esigenze per un diploma secondu GOST. Se sapete cumu, pudete mudificà u mudellu per adattà à i vostri bisogni. In i mo struzzioni, prima vi tuccherà à schernà cù l'impostazione PSCyr in TexLive. A cunfigurazione hè fatta in a distribuzione Linux Mint Mate, per altre distribuzioni pudete avè da google i cartulare di pacchetti TexLive standard per u vostru sistema.
Installazione di TexLive
Di sicuru, pudete installà solu i parti necessarii di stu pacchettu. Ma personalmente, eru francamente troppu pigro per circà l'installazione minima di travagliu necessariu. Per assicurà chì tuttu funziona, stallate tuttu u pacchettu TexLive. Hè chjamatu texlive-full è pesa un pocu più di 2 gigabytes, tenite stu fattu in mente. Eseguimu u cumandimu:
user@hostname:~$ sudo apt install texlive-full -y
Dopu una stallazione abbastanza longa, pudete passà à u prossimu articulu.
Stallà u Pandoc Converter
Pandoc hè un pacchettu Linux chì permette di cunvertisce certi formati di testu à altri. Havi assai caratteristiche interessanti chì pudete truvà in Internet. Ci interessa solu a pussibilità di cunvertisce un schedariu di marcatu in PDF. Verificate se Pandoc hè stallatu è, se no, installate. Per esempiu cusì:
user@hostname:~$ dpkg -s pandoc
Se l'output dice chì ùn hè micca stallatu, installate:
user@hostname:~$ sudo apt install pandoc -y
Stallà u pacchettu PSCyr per TexLive
Prima avete bisognu di scaricà PSCyr. Per avà hè sempre dispunibule in questu
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
Dopu, scopre induve si trova u repertoriu lucale texmf. Eseguimu u cumandimu:
user@hostname:~$ kpsewhich -expand-var='$TEXMFLOCAL'
Probabilmente avete stu cartulare - /usr/local/share/texmf/, e poi facemu:
user@hostname:~$ sudo cp -R ./PSCyr/* /usr/local/share/texmf/
Ebbè, o ùn pudete micca disturbà è eseguisce un cumandamentu chì copiarà in un cartulare texmf induve ella hè:
user@hostname:~$ sudo cp -R ./PSCyr/* $(kpsewhich -expand-var='$TEXMFLOCAL')
I fonts PSCyr installati, cunnette à TexLive:
user@hostname:~$ sudo texhash
user@hostname:~$ updmap --enable Map=pscyr.map
user@hostname:~$ sudo mktexlsr
Template LaTeX per a cunversione md2pdf
Ùn scriveraghju micca esattamente cumu hè cunfiguratu stu mudellu, è solu daraghju sottu u spoiler senza assai spiegazione. Basta à dì chì hè bè cunfigurata, almenu in quantu à cumu si tratta di testi cù assai codice fonte. Se ùn site micca cuntentu cù a dimensione di l'indentazioni, a spaziatura di a linea, a mancanza di numerazione di rùbbriche è sottosezzioni, allora in u mo parè hè abbastanza faciule per google a quistione in Internet "cumu per fà in Latex ..." è allora u vostru bisognu. S'ellu ùn hè micca chjaru, scrivite in i cumenti, pruvaraghju à sfondà in i mo paràmetri 4 anni fà è discrive quale linea di u mudellu hè rispunsevule per ciò chì. Intantu, scriveraghju cumu l'aghju fattu nantu à u mo PC, è site liberu di ripetiri o mudificà per sè stessu.
Crea un schedariu mudellu.tex in u catalogu /usr/share/texlive/:
user@hostname:~$ sudo touch /usr/share/texlive/template.tex
Dà i permessi di leghje:
user@hostname:~$ sudo chmod 444 /usr/share/texlive/template.tex
apre u sottu à a radica è incollà u cuntenutu oculatu sottu u spoiler sottu in questu:
user@hostname:~$ sudo nano /usr/share/texlive/template.tex
U cuntenutu di u mudellu /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@{}}#2end{tabular}}
setpapersize{A4}
setmarginsrb {1cm}{1cm}{1cm}{1cm}{0pt}{0mm}{0pt}{13mm}
usepackage{indentfirst}
setlengthparindent{1cm}
renewcommand{baselinestretch}{1}
renewcommandthechapter{}
renewcommandthesection{}
renewcommandthesubsection{}
renewcommandthesubsubsection{}
titleformat
{chapter} % command
{bfseriesnormalsizecentering} % format
{thechapter} % label
{0.5ex} % sep
{
centering
}
[
vspace{-1.5ex}
] % after-code
titleformat
{section}
[block]
{normalfontbfseries}
{thesection}{0.5em}{}
sloppy
letoldenumerateenumerate
renewcommand{enumerate}{
oldenumerate
setlength{itemsep}{1pt}
setlength{parskip}{0pt}
setlength{parsep}{0pt}
}
letolditemizeitemize
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=footnotesizettfamily,
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)$
renewcommandbibname{$biblio-title$}
$else$
renewcommandrefname{$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}
Salvà u schedariu /usr/share/texlive/template.tex è scrivite un script chì cunvertisce u schedariu Makrdown in PDF, creendu in u stessu cartulare un schedariu chjamatu Markdown cù u prefissu .pdf, vale à dì dopu a cunversione. filename.md apparirà in u cartulare. filename.md.pdf. Chjamemu u script md2pdf è mette in strada / usr / bin. Eseguimu i cumandamenti in sequenza:
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
A 4a linea cuntene veramente u cumandamentu di cunversione. fate attenzione à --from=markdown_github. A versione GitHub di Markdown hè cumpatibile cù u Markdown uriginale, cusì se u vostru testu hè scrittu in questu, ùn avete micca da preoccupari. Se u vostru schedariu MD hè scrittu in un dialettu Markdown specificu, allora leghjite u manuale Pandoc (man pandoc
), assicuratevi chì a vostra implementazione hè supportata da ellu, è tweak /usr/bin/md2pdf se ne necessariu.
Script per a stallazione più o menu automatica
Se ùn vulete micca veramente cunfigurà nunda in tuttu, è avete una distribuzione cum'è Ubuntu, pudete pruvà à creà un script cù u cuntenutu oculatu sottu u spoiler, è più prubabilmente tuttu s'installa, l'unicu hè, copia. u mudellu TeX publicatu sottu u spoiler sopra à induve avete bisognu. Aprite Terminale è eseguite:
user@hostname:~$ cd
user@hostname:~$ touch installmd2pdf.sh
Allora riempia cù u cuntenutu seguente:
U cuntenutu di u script $HOME/installmd2pdf.sh
#!/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
Eseguite cù u cumandimu:
user@hostname:~$ sudo bash $HOME/installmd2pdf.sh
Ùn vi ne scurdate micca /usr/share/texlive/template.tex deve esse cumpletu cum'è indicatu in a sezione "Template LaTeX per a cunversione md2pdf» cuntenutu.
Utilizà md2pdf
Basta à apre u cartulare cù u schedariu Markdown (some_file.md) in u Terminal è eseguite u cumandimu:
user@hostname:~$ md2pdf some_file.md
In u risultatu, un schedariu apparirà in u cartulare some_file.md.pdf.
cunchiusioni
Basatu nant'à u metudu discrittu, vi ponu custruisce ogni stile di schedari PDF, vi ponu dinù cunvertisce altri furmati invece di md, ogni supportatu da Pandoc. Averu speru chì un ghjornu sta struzzione serà utile à 3 persone è mezu.
Source: www.habr.com