I'm a copy editor. For editing reasons I find usefull to spot certain commands used by authors (or by myself in the editing process) directly in the .pdf (or .dvi) file (I know that I can highlight them in my text editor etc., but I have my reasons to do it in this way).
For example, sometimes I need to spot pagebreak commands like \pagebreak, \newpage, \clearpage etc. These commands do not produce a "visible" output in the .pdf (or .dvi) file.
I do something like:
latex "\AtBeginDocument{\let\Oldpagebreak\pagebreak \
\renewcommand{\pagebreak}{\marginpar{\colorbox{red}{pagebreak}}\Oldpagebreak}} \input{file.tex}"
doing so I can pass the string:
\let\Oldpagebreak\pagebreak
\renewcommand{\pagebreak}{\marginpar{\colorbox{red}{pagebreak}}\Oldpagebreak}
to the LaTeX engine without changing the source file.
This is what I get in the .pdf (or .dvi) file:
My problem is that \marginpar has some issues used in this way.
I have warnings like:
LaTeX Warning: Marginpar on page 23 moved.If the command is used in a floating environment I got the error:
! LaTeX Error: Not in outer par mode.
My question is how can I avoid these warnings/errors?
Note. I'm opend to other ideas. The most important thing is that the general layout of the document (except for the commands revelation) must remain unchanged.
Edit after the campa and daleif comments.
I tried with the marginnote package. It solved the warnings/error issues.
This is a MWE (for convenience I put the commands in the premble):
\documentclass[11pt]{article}
\usepackage{amsmath}
\pagestyle{empty}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{marginnote}
\let\Oldsmallskip\smallskip
\renewcommand{\smallskip}{\marginnote{\colorbox{red}{smallskip}}\Oldsmallskip}
\let\Oldmedskip\medskip
\renewcommand{\medskip}{\marginnote{\colorbox{red}{medskip}}\Oldmedskip}
\let\Oldbigskip\bigskip
\renewcommand{\bigskip}{\marginnote{\colorbox{red}{bigskip}}\Oldbigskip}
\let\Oldpagebreak\pagebreak
\renewcommand{\pagebreak}{\marginnote{\colorbox{red}{pagebreak}}\Oldpagebreak}
\let\Oldnewpage\newpage
\renewcommand{\newpage}{\marginnote{\colorbox{red}{newpage}}\Oldnewpage}
\let\Oldclearpage\clearpage
\renewcommand{\clearpage}{\marginnote{\colorbox{red}{clearpage}}\Oldclearpage}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=.3\linewidth]{example-image}
\medskip
\caption{Example image.}
\end{figure}
\section{Section 1}
\blindtext
\medskip
\section{Section 2}
\blindtext
\pagebreak
\section{Section 3}
\blindtext
\end{document}
A diffpdf didn't show any problem:



\clearpageshould never appear in a floating environment anyway. Maybe the packagemarginnotecould help, but it would be really helpful to have some document which actually displays the problems. (BTW: I'm not the downvoter, though I think the question has some margin for improvement.) – campa Jun 24 '20 at 14:49marginnotewith the macro of the same name. It uses non floating margin pars. – user187802 Jun 24 '20 at 14:52marginnote, for me through thefixmepackage. Again this does not move if there are several notes in the same place, but it is actually easy to add an extra option to\fxnoteto manually move a note up and down. – daleif Jun 24 '20 at 14:52\fxnotesetup is my most used copyediting tool. The tikz and global position I use if I only have access to the PDF. – daleif Jun 24 '20 at 14:53\marginparinside figure environment fails? – campa Jun 25 '20 at 09:54