All Projects → liffiton → code2tex

liffiton / code2tex

Licence: MIT license
Convert source code to a LaTeX document / PDF with syntax highlighting and line numbers.

Programming Languages

python
139335 projects - #7 most used programming language
TeX
3793 projects
java
68154 projects - #9 most used programming language
Ada
118 projects
C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to code2tex

ZenScript
Visual Studio Code extension/Language Server for ZenScript, includes highlight, code snippet and language server(WIP). Works with 👇
Stars: ✭ 29 (+20.83%)
Mutual labels:  syntax-highlighting
vscode-ibmi-languages
Syntax highlighting for IBM i languages such as RPG, CL, DDS, MI, and RPGLE fixed/free.
Stars: ✭ 28 (+16.67%)
Mutual labels:  syntax-highlighting
SubLilyPond
LilyPond syntax highlighting in Sublime Text 2 and 3.
Stars: ✭ 26 (+8.33%)
Mutual labels:  syntax-highlighting
vim-SystemVerilog
SystemVerilog syntax highlight/indent support in vim
Stars: ✭ 37 (+54.17%)
Mutual labels:  syntax-highlighting
Better-Less
Cross-compatible syntax highlighting for Less
Stars: ✭ 13 (-45.83%)
Mutual labels:  syntax-highlighting
VisualStudio-ColorCoder
Visual Studio extension that helps with semantic highlighting in C# and VB.Net
Stars: ✭ 31 (+29.17%)
Mutual labels:  syntax-highlighting
newsroom
A simple, minimalistic Hugo theme. View Demo here
Stars: ✭ 200 (+733.33%)
Mutual labels:  syntax-highlighting
myPDDL
PDDL Syntax Highlighting, Snippets, Domain Visualization and more for Sublime Text
Stars: ✭ 32 (+33.33%)
Mutual labels:  syntax-highlighting
Fragaria
Cocoa syntax highlighting text view
Stars: ✭ 53 (+120.83%)
Mutual labels:  syntax-highlighting
CodeView
Android Library to make it easy to create an Code editor or IDE that support any languages and themes, with auto complete, auto indenting, snippets and more features
Stars: ✭ 254 (+958.33%)
Mutual labels:  syntax-highlighting
iterm-oh-my-zsh-powerlevel10k
Improved Terminal Experience with Oh My Zsh, iTerm2, PowerLevel10K
Stars: ✭ 24 (+0%)
Mutual labels:  syntax-highlighting
go-highlight
A Go (Golang) code syntax highlighting library.
Stars: ✭ 20 (-16.67%)
Mutual labels:  syntax-highlighting
intellij-prisma
Prisma schema file support for IntelliJ IDEs (WebStorm, PHPStorm, Pycharm, RubyMine, ...)
Stars: ✭ 25 (+4.17%)
Mutual labels:  syntax-highlighting
SublimeText-GameMaker-Plugin
GML Snippets & Syntax Highlighting for SublimeText 2
Stars: ✭ 20 (-16.67%)
Mutual labels:  syntax-highlighting
lammps vscode
VSCODE extension for language support of LAMMPS scripts
Stars: ✭ 26 (+8.33%)
Mutual labels:  syntax-highlighting
KeyLighter
Yet another syntax highlighter for PHP
Stars: ✭ 29 (+20.83%)
Mutual labels:  syntax-highlighting
editor
A text editor written in Nim
Stars: ✭ 24 (+0%)
Mutual labels:  syntax-highlighting
sql-heredoc.vim
Syntax highlighting for SQL heredocs.
Stars: ✭ 19 (-20.83%)
Mutual labels:  syntax-highlighting
hgrep
Grep with human-friendly search results
Stars: ✭ 335 (+1295.83%)
Mutual labels:  syntax-highlighting
misbehave
Add IDE-like text entry to HTML contenteditable tags
Stars: ✭ 34 (+41.67%)
Mutual labels:  syntax-highlighting

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, but I have added support for the language thanks to Gary Hammock). For any language that does not have syntax highlighting rules, the file will simply be included as monospaced black text.

Alternatives

  • render50 - Developed for Harvard's CS50 course. Solves the same problem with different tools.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].