Pandoc, crear un solo MD y exportar a PDF
cadirPro
En Markdown, lo ideal para unir capítulos es crear un solo MD y exportar a PDF con Pandoc. Es exactamente para lo que está hecho.
Nivel editorial, usaremos:
- Pandoc
- Motor LaTeX xelatex
- Plantilla personalizada
- Fuente profesional (Libertinus o EB Garamond)
Instalar lo necesario
En tu PC LOCAL:
sudo apt install pandoc texlive-xetex texlive-fonts-recommended texlive-latex-extra
sudo apt install fonts-libertinus # Opcional (no existe):
sudo apt install fonts-linuxlibertine # Opcional (fuente muy buena)
Creamos plantilla editorial
mkdir -p ~/web/cadizpro.com/templates-pdf
nano ~/web/cadizpro.com/templates-pdf/libro.tex
Contenido de libro.tex
\documentclass[11pt,oneside]{book}
\usepackage[a4paper,margin=2.8cm]{geometry}
\usepackage{fontspec}
\usepackage{titlesec}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{setspace}
\usepackage{tocloft}
\setmainfont{Libertinus Serif}
\onehalfspacing
% Encabezados
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\thepage}
\fancyhead[L]{\nouppercase{\leftmark}}
\renewcommand{\headrulewidth}{0pt}
% Estilo capítulos
\titleformat{\chapter}[display]
{\normalfont\Huge\bfseries}
{\chaptername\ \thechapter}
{20pt}
{\Huge}
\hypersetup{
colorlinks=true,
linkcolor=black,
urlcolor=blue
}
\begin{document}
% Portada
\begin{titlepage}
\centering
\vspace*{4cm}
{\Huge\bfseries $title$\par}
\vspace{1.5cm}
{\Large Guía completa\par}
\vfill
{\large $author$\par}
\vspace{0.5cm}
{\large cadizpro.com\par}
\end{titlepage}
\tableofcontents
\clearpage
$body$
\end{document}
Ensayo minimalista editorial, otra plantilla. libro-minimal.tex
nano ~/web/cadizpro.com/templates-pdf/libro-minimal.tex # Editar plantilla
\documentclass[12pt,oneside]{book}
\usepackage[a4paper,top=3.5cm,bottom=3.5cm,left=3.2cm,right=3.2cm]{geometry}
\usepackage{fontspec}
\usepackage{titlesec}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{setspace}
\def\tightlist{}
% Fuente elegante y sobria
\setmainfont{Linux Biolinum O}
% Interlineado cómodo
\setstretch{1.25}
% Quitar numeración en capítulos
\titleformat{\chapter}[block]
{\normalfont\huge\bfseries}
{}
{0pt}
{}
% Cabecera limpia
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\hypersetup{
colorlinks=false,
hidelinks
}
\begin{document}
% PORTADA MINIMALISTA
\thispagestyle{empty}
\vspace*{5cm}
\begin{center}
{\Huge\bfseries $title$}
\vspace{1.5cm}
{\large $author$}
\vfill
{\small cadizpro.com}
\end{center}
\clearpage
\tableofcontents
\clearpage
$body$
\end{document}
En tu pc LOCAL
script
nano ~/web/scripts/build-book-minimalista-serie-pdf.sh
Pegar:
#!/bin/bash
# ==============================
# build-serie-pdf.sh
# Genera un PDF a partir de una serie Zola
# Uso:
# ./build-serie-pdf.sh netiqueta-en-whatsapp
# ==============================
set -e
SITIO=cadizpro.com
BASE_WEB=/home/u1001/web
BASE=$BASE_WEB/$SITIO
SERIE=$2
CARPETA_SERIE=$1
if [ -z "$SERIE" ]; then
echo "Uso: ./build-serie-pdf.sh carpeta-serie nombre-serie"
exit 1
fi
if [ -z "$CARPETA_SERIE" ]; then
echo "Uso: ./build-serie-pdf.sh carpeta-serie nombre-serie"
exit 1
fi
SRC="$BASE/content/series/$CARPETA_SERIE"
OUT="$BASE/content/series/$CARPETA_SERIE/$SERIE"
TMP="$BASE_WEB/scripts/tmp-$SERIE.md"
PDF="$OUT-100/cadizpro.com-$SERIE.pdf"
#mkdir -p "$OUT"
#echo "" >> "$TMP"
#echo " ${SERIE//-/ }" > "$TMP"
#echo "" >> "$TMP"
#echo "Guía completa — cadizpro.com" >> "$TMP"
#echo "" >> "$TMP"
#echo "---" >> "$TMP"
# Buscar capítulos ordenados
find "$SRC" -type d -name "$SERIE-*" | sort | while read dir; do
echo "Procesando $dir"
# Extraer título y descripción del front matter
TITULO=$(grep '^title' "$dir/index.md" | head -1 | sed 's/title *= *"\(.*\)"/\1/')
DESCRIPCION=$(grep '^description' "$dir/index.md" | head -1 | sed 's/description *= *"\(.*\)"/\1/')
echo "" >> "$TMP"
#echo "## $(basename "$dir")" >> "$TMP"
#echo "" >> "$TMP"
echo "## $TITULO" >> "$TMP"
if [[ -n "$DESCRIPCION" ]]; then
echo "" >> "$TMP"
echo "*$DESCRIPCION*" >> "$TMP"
fi
echo "" >> "$TMP"
echo "$(basename "$dir")" >> "$TMP"
echo "" >> "$TMP"
# Quitar front matter
sed '/^+++/,/^+++/d' "$dir/index.md" >> "$TMP"
echo "" >> "$TMP"
echo "---" >> "$TMP"
echo "" >> "$TMP"
done
pandoc "$TMP" \
-o "$PDF" \
--pdf-engine=xelatex \
--template="$BASE_WEB/templates-pdf/libro-minimal.tex" \
--toc \
--number-sections \
--metadata title="$SERIE" \
--metadata author="cadizPro"
rm "$TMP"
echo ""
echo "PDF generado correctamente:"
echo "$PDF"
Hazlo ejecutable
chmod +x ~/web/scripts/build-book-minimalista-serie-pdf.sh # permisos
Generar el PDF
cd ~/web/scripts
./build-book-minimalista-serie-pdf.sh normas-de-uso-whatsapp netiqueta-en-whatsapp
Ventajas del sistema
- No duplicas contenido
- Siempre actualizado
- Automatizable
- Escalable a cualquier serie
- Independiente