{"id":17316723,"url":"https://github.com/liffiton/code2tex","last_synced_at":"2025-04-14T14:22:05.995Z","repository":{"id":1337091,"uuid":"1282992","full_name":"liffiton/code2tex","owner":"liffiton","description":"Convert source code to a LaTeX document / PDF with syntax highlighting and line numbers.","archived":false,"fork":false,"pushed_at":"2021-10-27T19:05:12.000Z","size":169,"stargazers_count":26,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-14T14:21:58.505Z","etag":null,"topics":["code-highlight","syntax-highlighting"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liffiton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-01-22T21:32:58.000Z","updated_at":"2024-06-24T16:16:11.000Z","dependencies_parsed_at":"2022-08-16T13:10:26.303Z","dependency_job_id":null,"html_url":"https://github.com/liffiton/code2tex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liffiton%2Fcode2tex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liffiton%2Fcode2tex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liffiton%2Fcode2tex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liffiton%2Fcode2tex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liffiton","download_url":"https://codeload.github.com/liffiton/code2tex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248894949,"owners_count":21179154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-highlight","syntax-highlighting"],"created_at":"2024-10-15T13:13:56.648Z","updated_at":"2025-04-14T14:22:05.940Z","avatar_url":"https://github.com/liffiton.png","language":"Python","readme":"# Code2Tex\n\nCode2Tex was created to aid in grading programming assignments.  It takes\nsource code and inserts it into a simple LaTeX document from which a PDF can be\nmade.  This provides a document with syntax highlighting and clear headings for\neach file that can be marked up and returned to the students.\n\nSyntax highlighting is provided via the\n[listings](https://www.ctan.org/pkg/listings) LaTeX package.  Not all languages\nare currently supported; the list of included languages is in the [package\ndocumentation](https://texdoc.org/serve/listings/0#page=13) (Javascript is a\nnotable exception, but I have added support for the language thanks to [Gary\nHammock](https://github.com/ghammock/LaTeX_Listings_JavaScript_ES6)).  For any\nlanguage that does not have syntax highlighting rules, the file will simply be\nincluded as monospaced black text.\n\n## Alternatives\n  * [render50](https://cs50.readthedocs.io/render50/) - Developed for Harvard's\n    CS50 course.  Solves the same problem with different tools.\n\n## Usage / Examples\n\nRun `code2tex.py` followed by any number of filenames.  It will output the\nLaTeX document to standard out, which may be redirected to a file:\n\n    ./code2tex.py file [file [file [...]]] \u003e output.tex\n\nThis will create `output.tex`, ready to pass to `pdflatex` or `xelatex`.  For\nexample, if a student with user id \"jsmith\" submitted several java files:\n\n    ./code2tex.py jsmith*.java \u003e jsmith.tex\n    pdflatex jsmith.tex\n\nThis would create a PDF named `jsmith.pdf` containing the contents of all\n`jsmith*.java` files, nicely formatted with syntax highlighting and a separate\nheader for each.\n\nIf you have UTF-8 characters in a filename or within an included file, use\n`xelatex` in place of `pdflatex` for better unicode handling.  The output may\nlook better if you have the `lmodern` package installed as well.  This should\nwork for Latin characters, but non-Latin characters may still render\nincorrectly within a file listing.\n\nWildcards and [brace\nexpansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html)\ncan be used to quickly grab files of multiple extensions from within a folder:\n\n    ./code2tex.py codefolder/*.{html,css,js} \u003e code.tex\n\nOr from multiple nested folders:\n\n    ./code2tex.py codefolder/*/*.{html,css,js} \u003e code.tex\n\nSee the `hello_worlds` folder for example output; `hello_world.tex` and\n`hello_world.pdf` were created from the various \"Hello, World!\" programs in\nthat directory.  The syntax highlighter recognizes a wide variety of\nprogramming languages.\n\n### convert_all.py\n\nTo quickly convert all user submissions downloaded from a [Moodle](https://moodle.org/) or [Canvas](https://www.canvaslms.com/) assignment:\n 1. Use the \"Download submissions\" option in a Moodle or Canvas assignment and extract the resulting zip file.\n 2. run `convert_all.py \u003cdirectory\u003e` where `\u003cdirectory\u003e` is the directory with the unzipped files.\n\nThe script will attempt to create PDFs from all the files. It parses the\nfilenames constructed from Moodle and outputs PDFs named\n\"[Name]\\_[ID]\\_files.pdf\".\n\n## Dependencies\n\nThe python scripts require Python 3 and have no other dependencies.\n\nProducing a PDF of the LaTeX output requires LaTeX.  Code2tex's output depends\non a few packages that are not always included by default in a LaTeX install;\nin Ubuntu, for example, you'll need to install the following packages (along\nwith their dependencies):\n\n    texlive-fonts-recommended\n    texlive-latex-extra\n    texlive-latex-extra-doc\n    texlive-math-extra\n    texlive-pictures-doc\n\nInstall these with the following command:\n\n    sudo apt-get install texlive-fonts-recommended texlive-latex-extra texlive-latex-extra-doc texlive-math-extra texlive-pictures-doc\n\nOn other systems, you will need to find the correct packages.  Look for\n\"[latex]-extra\" and \"math-extra\" packages.\n\n## Marking up PDFs\n\nOnce you have a PDF, various software can be used to mark it up.  I and my TAs\nhave had success with [PDF-XChange\nViewer](http://www.tracker-software.com/product/pdf-xchange-viewer), the best\nfree Windows software I've found for annotating PDFs.  It has a wide range of\ntools for creating text boxes, circling things, pointing with arrows, etc.  In\nLinux, [Xournal](http://xournal.sourceforge.net/) is a decent option.  Please\nlet me know if you find other applications that work well for this.\n\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliffiton%2Fcode2tex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliffiton%2Fcode2tex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliffiton%2Fcode2tex/lists"}