Giter Site home page Giter Site logo

covermaker's Introduction

covermaker

Script to create PDF file covers using a LaTeX template and Python from a JSON.

Dependencies

  • Python: This project uses only the Python Standard Libary (tested on Python >= 3.4).
  • Others: covermaker.py needs to have pdflatex installed. pdflatex is included in the TeX Live LaTeX distribution.

How does it works?

cover_template.tex plays as a template using tokenized variables like $variable which will be replaced by the data set in the JSON file.

Tokenized variable in the LaTeX template:

\textsc{\LARGE $university} % Name of your university/college

Thanks to Python's Template strings (see the docs and the PEP 292) the scrip replaces the $variable with the dictionary (when JSON is loaded) value asigned to the "variable" dictionary key.

JSON object example:

{
"university" : "Technische Univesität München",
"subject" : "Flugsystemdynamik 1",
"document" : "Lehrstuhls für Flugsystemdynamik (FSD)",
"title" : "Flight System Dynamics 1 notes",
"name" : "Pablo",
"surname" : "Rodríguez Robles",
"email" : "[email protected]",
"date" : "21. September 2016"
}

Iterating over the JSON array to get each object:

for cover in data["covers"]:
      create(cover)

Creating template and substituting:

# This code is inside the create() function
with open('cover_template.tex', 'r') as p:
        template = p.read()
t = Template(template)
doc = t.substitute(cover)

The script creates the file cover.tex with the variables replaced:

\textsc{\LARGE Technische Universität München} % Name of your university/college

Running a subprocess we call pdflatex and create the cover.pdf which is placed in the output directory.

subprocess call() used to call pdflatex:

# This code is inside the create() function
subprocess.call(['pdflatex',                   # Using pdflatex
                 '-output-directory=./output',
                 './.temp/cover%d.tex' % n],   # cover.tex destination's path
                 stdout=open(os.devnull, 'wb') # Disables pdflalatex's text output
                )

covermaker's People

Contributors

pablordrrbl avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.