Coder Social home page Coder Social logo

difftotex's Introduction

difftotex

Useful when teachers require that you "include in the report the most important code that you yourself wrote or modified."

For each file it creates a heading (like section/subsection -- is customizeable) and a label with the filename (also customizeable)

Requirements

  • Python 3.2+
  • a TeX enviroment

Usage

$ git diff --no-color > somefile.diff
$ SOMEPATH/difftotex.py somefile.diff

or

$ git diff --no-color | SOMEPATH/difftotex.py

This will create the file diff.tex in your current directory.

Help me create a diff!

========================

To change the path of output file, use the -o options, like so

$ SOMEPATH/difftotex.py -o path/output.tex somefile.diff

- adding options to the end is also accepted

========================

To learn about the "advanced" options run SOMEPATH/difftotex.py --help (like changing the section level to "subsubsection")

Latex

Include the following in your preabmle

\usepackage{array}
\usepackage{tabu}
\usepackage{longtable}
\usepackage[table]{xcolor}

and then input the diff

\input{diff.tex}

Example

Here is a small example for a libgit2 commit -- below is a preview of the pdf

examplepng

Known Limitations

  • Can only parse git diffs (not other formats)
  • Will completely ignore binary files listed in the diff
  • Tab size is fixed to 4 spaces
  • TeX code gets really ugly (special characters are escaped manually, due to the fact that I couldn't find a combination of multipage tables working with an in-cell verbatim enviroment)

FAQ for generating diffs

Basics

You need to specify a reference to the commit you want to base your diff on, lets call it <start-commit>. To generate the diff up till the current commit, simply run git diff --no-color start-commit -- you can also specify a commit to end at, as git diff --no-color start-commit end-commit

How do I find a reference to the initial commit?

run git rev-list --max-parents=0 HEAD to list all root commits (there can be more than one)

Only include some subfolders

If you want to restrict paths included, e.g. only include folders src and data, run git diff --no-color start-commit end-commit -- src data

Don't use full path from project root.

When you want <git-project>/src/file.c listed as file.c, cd to <git-project>/src/ and add the --relative option. (will restrict diff to current folder and subfolders)

For changes I have made, include the whole file

Add the option -U10000000 (will include the nearst 10,000,000 lines of code)

For changes I have made, include the whole function

Add the option -W

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.