Objective / Question
I write technical reports. Our company requires that changed text be marked. The preferred way to do this is with a vertical bar to the side of any changed line, like so:
I’d like to be able to run something like git diff --color-words
on a typst document to mark the changes, then use regex or show rules to replace the terminal color codes with Typst functions to add vertical bars next to any changed lines. (I’m aware manual cleanup would be necessary in some cases)
What’s the best way to implement this in Typst?
What I’ve tried
The drafting and pinit packages seem to have useful functions here (thanks to Nathan Jessurun and orangeX4!). I can use pinit’s pins to mark the extents of my change and edit the pinit-line function to draw the revbar (code below) but I haven’t been able to generalize this to encompass changes across pagebreaks. Additionally, my pinit approach currently requires uniquely named pins, which will be painful to deal with in any kind of regex/show rule solution.
#import "@preview/pinit:0.2.2":*
#set page("a5")
#let side-line(
stroke: gray+0.5pt,
start-dx: 0pt, start-dy: 0pt, end-dx: 0pt, end-dy: 0pt,
start, end,
) = {
pinit(
start,
end,
callback: (start-pos, end-pos) => {
absolute-place(
line(
stroke: stroke,
start: (13.5cm, start-pos.y + start-dy - 12pt,),
end: (13.5cm, end-pos.y + end-dy + 3pt,
),
),
)
},
)
}
#lorem(12)
#pin("begin_change") #box(side-line("begin_change","end_change"))
#lorem(4)
#pin("end_change")
#lorem(12)
I’ve experimented with adapting the pinit
function to use a default end-of-page pin when it could not find the end-change
pin on a page. However, this made the typst layout unstable when the change spanned a pagebreak.
Thanks in advance for any help you can offer!