latexdiff icon indicating copy to clipboard operation
latexdiff copied to clipboard

citation in the margin

Open Adeline-Lacroix opened this issue 4 years ago • 5 comments

Hi,

Latexdiff is working perfectly except that long citation extend off the page, in the margin.

I tried to solve the problem using the microtype package and \begin{sloppypar}....\end{sloppypar} but it did not worked...

I also tried to use latexdiffcite (, but it did not worked neither as I got an error regarding the bibliography that I did not have with latexdiff.

(I am on mac Monterey).

Any help would be much appreciated...

Adeline-Lacroix avatar Feb 01 '22 14:02 Adeline-Lacroix

This is a known limitation. I cite from the documentation of latexdiff:

There is an incompatibility between the C package, which C uses for underlining and striking out in the UNDERLINE style, the default style, and the way citations are generated. In order to be able to mark up citations properly, they are enclosed with an C<\mbox> command. As mboxes cannot be broken across lines, this procedure frequently results in overfull boxes, possibly obscuring the content as it extends beyond the right margin. The same occurs for some other packages (e.g., siunitx). If this is a problem, you have two possibilities.

  1. Use C<CFONT> type markup (option C<-t CFONT>): If this markup is chosen, then changed citations are no longer marked up with the wavy line (additions) or struck out (deletions), but are still highlighted in the appropriate color, and deleted text is shown with a different font. Other styles not using the C package will also work.

  2. Choose option C<--disable-citation-markup> which turns off the marking up of citations: deleted citations are no longer shown, and added citations are shown without markup. (This was the default behaviour of latexdiff at versions 0.6 and older)

Unfortunately, still I am not aware of a better solution. But as the real solution to this lies probably with ulem and so beyond my control. For completeness sake: in the past I had investigated the soul package as an alternative means to achieve underlining and strike-out. This seemed to cope with the citations, but did not work with equations. I decided that longer citations causing overfull boxes and running outside the right margin was the lesser evil but if you happened to not rely on equations, then it might be an option for you to define a custom style based on soul.

As it's technically an an unsolved issue, I will not close it, but gave it the "WONTFIX" label to indicate that I currently see no way to address this (except doing the citation processing outside latex, the approach of latexdiffcite. Unfortunately latexdiffcite seems to have been abandoned by its developer.

ftilmann avatar Feb 06 '22 22:02 ftilmann

Closed as Duplicate of #188

ftilmann avatar Feb 08 '22 06:02 ftilmann

FYI @ftilmann, following #277 (swap ulem for lua-ul), using LuaLaTeX, and removing mboxes manually in the generated diff .tex file did the trick for me (that is, I finally got colored/decorated long citations that nicely wrap at the expected line break). Given the (low?) likelhihood that there is a ulem package fix, maybe this is the way forward to workaround/fix #17, #60, #188, #255, #270, and maybe other issues (e.g., for commands that don't work nicely with \mboxes)?

briochemc avatar Mar 18 '24 13:03 briochemc

Yes, indeed this looks like a way forward - I will need to test this and then put some logic in that does the markup correctly if lua-ul is imported, as I understand some commands have to be adapted

ftilmann avatar Mar 18 '24 14:03 ftilmann

Let me know if I can help. I would have attempted a PR but am a bit overwhelmed by the code.

Apart from @michaelmhoffman's changes to the preambles, I can see some logic in the code for when ulem is not used, but I'm not entirely sure if that would work as is:

https://github.com/ftilmann/latexdiff/blob/535ca8e19fe52f7bdc55d36cf5d3d669a63c5f02/latexdiff#L1347-L1349

briochemc avatar Mar 19 '24 23:03 briochemc

As there is a solution now when using lualatex and I can't do anything about the limitations of ulem, I am closing this

ftilmann avatar Aug 25 '24 12:08 ftilmann