Git Product home page Git Product logo

code2tex's Introduction

Code2Tex

Code2Tex was created to aid in grading programming assignments. It takes source code and inserts it into a simple LaTeX document from which a PDF can be made. This provides a document with syntax highlighting and clear headings for each file that can be marked up and returned to the students.

Syntax highlighting is provided via the listings LaTeX package. Not all languages are currently supported; the list of included languages is in the package documentation (Javascript is a notable exception). For any language that does not have syntax highlighting rules, the file will simply be included as monospaced black text.

Usage / Examples

Run code2tex.py followed by any number of filenames. It will output the LaTeX document to standard out, which may be redirected to a file:

./code2tex.py file [file [file [...]]] > output.tex

This will create output.tex, ready to pass to pdflatex or xelatex. For example, if a student with user id "jsmith" submitted several java files:

./code2tex.py jsmith*.java > jsmith.tex
pdflatex jsmith.tex

This would create a PDF named jsmith.pdf containing the contents of all jsmith*.java files, nicely formatted with syntax highlighting and a separate header for each.

If you have UTF-8 characters in a filename or within an included file, use xelatex in place of pdflatex for better unicode handling. The output may look better if you have the lmodern package installed as well. This should work for Latin characters, but non-Latin characters may still render incorrectly within a file listing.

Wildcards and brace expansion can be used to quickly grab files of multiple extensions from within a folder:

./code2tex.py codefolder/*.{html,css,js} > code.tex

Or from multiple nested folders:

./code2tex.py codefolder/*/*.{html,css,js} > code.tex

See the hello_worlds folder for example output; hello_world.tex and hello_world.pdf were created from the various "Hello, World!" programs in that directory. The syntax highlighter recognizes a wide variety of programming languages.

convert_all.py

To quickly convert all user submissions downloaded from a Moodle or Canvas assignment:

  1. Use the "Download submissions" option in a Moodle or Canvas assignment and extract the resulting zip file.
  2. run convert_all.py <directory> where <directory> is the directory with the unzipped files.

The script will attempt to create PDFs from all the files. It parses the filenames constructed from Moodle and outputs PDFs named "[Name]_[ID]_files.pdf".

Dependencies

The python scripts require Python 3 and have no other dependencies.

Producing a PDF of the LaTeX output requires LaTeX. Code2tex's output depends on a few packages that are not always included by default in a LaTeX install; in Ubuntu, for example, you'll need to install the following packages (along with their dependencies):

texlive-fonts-recommended
texlive-latex-extra
texlive-latex-extra-doc
texlive-math-extra
texlive-pictures-doc

Install these with the following command:

sudo apt-get install texlive-fonts-recommended texlive-latex-extra texlive-latex-extra-doc texlive-math-extra texlive-pictures-doc

On other systems, you will need to find the correct packages. Look for "[latex]-extra" and "math-extra" packages.

Marking up PDFs

Once you have a PDF, various software can be used to mark it up. I and my TAs have had success with PDF-XChange Viewer, the best free Windows software I've found for annotating PDFs. It has a wide range of tools for creating text boxes, circling things, pointing with arrows, etc. In Linux, Xournal is a decent option. Please let me know if you find other applications that work well for this.

code2tex's People

Contributors

alanrussian avatar astropeak avatar liffiton 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.