md-to-pdf.sh script is the heart of the ASIR-ISO build system. It orchestrates the conversion of Markdown source files into professionally formatted PDF documents for all 12 didactic units.
Script Location
The build script is located at:Basic Usage
The script must be run from the
bin/ directory or with the correct relative paths to source files and templates.Script Architecture
The script is organized into several key sections:1. Environment Setup
The script begins by preparing the output directory:2. Configuration Variables
Defines templates, paths, and pandoc options:3. Didactic Unit Definitions
Maps unit numbers to directory names:4. Helper Functions
Provides utilities for output formatting and file processing:say_ok(): Display success messages in greensay_error(): Display error messages in redsay_file(): Check file existence and report statusmake_teoria(): Generate theory PDFsmake_practicas(): Generate task PDFsmake_anexos(): Generate annex PDFsmove_pdfs(): Organize output files
5. Main Processing Logic
A case statement handles the user’s selection:Core Functions
make_teoria()
Combines all theory files into a single PDF:pandoc --template ${TEMPLATE_TEX} \
${PANDOC_OPTIONS} \
-o ${PDF_PATH}/${UDTEORIA}_Teoria.pdf \
Teoria_*.md
make_practicas()
Generates individual PDFs for each task:NUM=$(echo $ejer | cut -d "_" -f2 | cut -d "." -f1)
NOMBRE=$(echo $ejer | cut -d "_" -f3 | cut -d "." -f1)
pandoc --template ${TEMPLATE_TEX_TAREAS} \
${PANDOC_OPTIONS} \
-o ${PDF_PATH}/${UDPRACTICAS}_Tarea_${NUMP}_${NOMBRE}.pdf \
$ejer
make_anexos()
Works similarly tomake_practicas() but processes Anexo_*.md files using the annexes template.
move_pdfs()
Organizes generated PDFs into unit-specific folders:Pandoc Configuration
The script uses consistent pandoc options across all conversions:Pandoc Options Explained
Pandoc Options Explained
Font SizeSets the base font size to 12 points for comfortable reading.Main FontUses the Ubuntu font family for all text.PDF EngineUses XeTeX for Unicode support and modern typography.TemplateApplies custom LaTeX template for consistent styling.
Installation Guides
Some units include installation guides that are processed alongside regular materials:Output Structure
After running the script, PDFs are organized as follows:Status Indicators
The script uses color-coded output to show progress:RED='\033[0;31m'GREEN="\033[0;32m"NC='\033[0m'(No Color)
Customization
Changing Font Size
Modify thePANDOC_OPTIONS variable:
Using Different Fonts
Change themainfont variable:
Ensure the font is installed on your system. Check with
fc-list | grep "FontName"Adding New Units
To add a 13th didactic unit:make_UD13(){
cd ${UD13_NAME}
make_teoria ${UD13_NAME}
make_practicas ${UD13_NAME}
cd ..
move_pdfs ${UD13_NAME}
}
Error Handling
The script includes basic error handling:exit 0: Successful completionexit 1: Unknown unit specified
Performance
Processing times vary by unit:- Single unit: 10-30 seconds
- All units: 3-5 minutes
- With guides: Additional 10-15 seconds per guide
Performance depends on the number of files, document length, and system resources.
Troubleshooting
Script Won’t Run
Problem: Permission denied Solution: Make the script executable:PDFs Not Generated
Problem: No output files Solution: Check that:- You’re running from the correct directory
- Source
.mdfiles exist in unit folders - Dependencies are installed (see Dependencies)
Template Not Found
Problem:--template error from pandoc
Solution: Verify template paths:
Wrong Output Location
Problem: PDFs appear in unexpected location Solution: The script usesreadlink -f to resolve absolute paths. Ensure you run it from bin/ directory.
Next Steps
Now that you understand the build scripts:- Review the Style Guide - Learn formatting conventions
- Check the Build Overview - Understand the complete workflow
- Try building a unit - Generate your first PDFs