1

I am using the changes package and building upont this question.

I basically want to have all the deleted and replaced text in (abbreviated) comments on the side. How can I do that?

See the example below. I want to achieve that result without having to type a comment to every replaced and deleted command and also want to make sure that the comments are abbreviated.

\documentclass{article}

\usepackage{changes}

\makeatletter
\setdeletedmarkup{\@gobble{#1}}
\makeatother

\begin{document}
Alas my love you do me \replaced[comment={(replaced): wrong}]{wrong}{right}, 
to cast me off\deleted[comment={(deleted): discourteously}]{discourteously}.
For I have loved you \replaced[comment={(replaced): well}]{badly}{well} \added{and poorly}, 
delighted in your \replaced[comment={(replaced): company}]{company}{corporation}.

To repeat: \deleted[comment={(deleted): Alas my love you do[...]}]{Alas my love you do me wrong, to cast me off discourteously.}

\listofchanges

\end{document}

enter image description here

BeSeLuFri
  • 109

1 Answers1

2

A partial attempt:

  • comment={...} is automatically set.
  • Font size in marginal notes is adjusted.
  • \truncateto{<num>}{<text>} is provided to truncate <text> to leave at most <num> words. Hope this helps.
\documentclass{article}

% control the fontsize
\PassOptionsToPackage{textsize=scriptsize}{todonotes}

\usepackage{changes}
\usepackage{xpatch}

%\usepackage{unravel}
%\unravelsetup{max-action=1000, max-input=1000, max-output=1000}
\providecommand\unravel[1]{#1}


% auto insert "comment"
\makeatletter
\xpatchcmd\replaced
  {\setkeys{Changes@replaced}{#1}}
  {\setkeys{Changes@replaced}{comment={(replaced): \protect\truncateto{6}{#2}}, #1}}
  {}{\fail}
\xpatchcmd\deleted
  {\setkeys{Changes@deleted}{#1}}
  {\setkeys{Changes@deleted}{comment={(deleted): \protect\truncateto{6}{#2}}, #1}}
  {}{\fail}

% fix \listofchanges
\xpatchcmd\ChangesListline
  {0px}
  {0pt}
  {}{\fail}


\newcounter{truncate}
\newcounter{truncate@max}

% truncate #2 to leave at most first #1 words
\def\truncateto#1#2{%
  \setcounter{truncate}{0}%
  \setcounter{truncate@max}{#1}%
  \truncate@loop{#2}%
}

\def\truncate@loop#1{%
  \ifnum\c@truncate=\c@truncate@max
    \def\next{[...]}% tail
  \else
    \in@{ }{#1}%
    \ifin@
      \stepcounter{truncate}%
      \truncate@split#1\@nil
    \else
      \def\next{#1}%
    \fi
  \fi
  \next
}

\def\truncate@split#1 #2\@nil{%
  \def\next{#1 \truncate@loop{#2}}%
}
\makeatother

\makeatletter
\setdeletedmarkup{\@gobble{#1}}
\makeatother


\begin{document}
Alas my love you do me \replaced{wrong}{right}, 
to cast me off\deleted{discourteously}.
For I have loved you \replaced{badly}{well} \added{and poorly}, 
delighted in your \replaced{company}{corporation}.

To repeat: \deleted{Alas my love you do me wrong, to cast me off discourteously.}

\listofchanges
\end{document}

enter image description here

More notes:

  • In \listofchanges, changes uses length unit px, which is added by pdfTeX but not supported by XeTeX. Hence I replace px with pt. See issue changes/#78 on GitLab.
muzimuzhi Z
  • 26,474