Skip to content

LaTeX #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,32 @@ diff_match_patch.prototype.diff_prettyHtml = function(diffs) {
};


/**
* Convert a diff array into a LaTeX report.
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
* @return {string} LaTeX representation.
*/
diff_match_patch.prototype.diff_latex = function(diffs,insertColor = 'Green', deleteColor = 'RedOrange') {
const latex = [];
for (let x = 0; x < diffs.length; x++) {
const op = diffs[x][0]; // Operation (insert, delete, equal)
const data = diffs[x][1]; // Text of change.
switch (op) {
case DIFF_INSERT:
latex[x] = '\\colorbox{' + insertColor + '}{' + data + '}';
break;
case DIFF_DELETE:
latex[x] = '\\st{\\colorbox{' + deleteColor+ '}{' + data +'}}';
break;
case DIFF_EQUAL:
latex[x] = data;
break;
}
}
return latex.join('');
};


/**
* Compute and return the source text (all equalities and deletions).
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
Expand Down