You have
\renewenvironment{figure}[1][2] {
\expandafter\origfigure\expandafter[H]
} {
\endorigfigure
}
and ask about white space. Almost every line could potentially add white space.
\renewenvironment{figure}[1][2]
this defines \begin{figure} to be an environment with one optional argument, if the option is not used then \begin{figure} is equivalent to \begin{figure}[2] (this was presumably not intended as 2 has no defined behaviour here) As the optional argument is not used at all, the default is arbitrary, perhaps [1][] would be clearer.
{
This adds a space token at the start of the definition, this could, depending where the figure is placed may produce a spurious additional line of white space in the resulting document. It is usually better to use {% so no space token is added to the definition.
\expandafter\origfigure\expandafter[H]
This expands the non expandable token H before calling \origfigure so this is equivalent to
\origfigure[H]
As above this adds a space token to the start of the environment, this is less likely to generate white space in the output, but again ending the line with % is good practice.
As #1 is not used the user-supplied or default positioning argument is ignored here and [H] is always used.
H by design produces bad white space at page breaks, as the reason for floating figures is to avoid bad page breaks and this disables that. A better alternative would be just to use \includegraphics directly as figure is only there to specify that the figure is a float (ie, may be moved). H (which was actually my idea originally:-) is just for final manual over-ride and manual positioning in final edit stages of a document, it should never be used as a default mechanism.
} {
Again the end of line here adds a space token and as in the first line this will produce white space in the output in some cases.
[H]disables floating so by design introduces bad white space that you choose to manually fix by moving the figure by hand in the source so that it appears in a good place with respect to page breaking. You are also adding additional white space tokens due to missing%at ends of lines in the definition, but using[H]would be the main issue. – David Carlisle Feb 10 '21 at 11:27\renewenvironment{figure}[1][2]makes the default value of the optional argument be[2]which would be an error except that you never use the optional argument at all. – David Carlisle Feb 10 '21 at 11:29\expandafter\origfigure\expandafter[HexpandsHwhich is not expandable, you can delete both\expandafteras they are doing nothing. – David Carlisle Feb 10 '21 at 11:31figureenvironment is to specify that the content may be moved.[H]makes sense as an occasional one-off over-ride but it doesn't make sense to make all figures do that, you may as well not use figure at all. I guess this question is a duplicate of https://tex.stackexchange.com/questions/8625/force-figure-placement-in-text – David Carlisle Feb 10 '21 at 11:50