# How to wrap pictures in lists in theorems with formulas?

I want text to flow pictures. @Bernard adviced me this way of doing it with formulas and theorems. Thanks him, it works great in many cases better than any other variants I have ever seen. I have reworked it for my wishes.

But there are several problems.

1. See the first prinscreen. Distance between left edge of paragraphs and left edge of the page are different! It is awful. Item 2 is natural. Text in the first item should be nearer to the left edge of paper.

the first:

1. See the second printscreen. Text in the second item is over picture! It is awful. and I do not want to add picture earlier in code. I want text in the second item to flow it. I mean that text relating to the second item should flow the picture relating to the first item. (solution to do \addpicture after the second item is not correct)

the second:

1. In my function I used very unprofessional (I guess) mechanism of labeling pictures. Can you advice me some better variants?

1. See the third printscreen and the second page of document. How cannot I do a new paragraph after proof here. I want word "Fusce" to follow "Proof" on the same line. I know that \leavevmode makes new line, but without it I get very bad result (you can see it at the fourth printscreen)

the third:

the fourth:

PS. If you know solution not using constructions below, please tell me.

PPS. In two words my questions are: How to make an ideal full automatic command of inserting pictures in latex? I want to make it as easy as possible.

PPPS. I have deleted quetion about odd and even pages, because it was solved: (If Then Else for odd page/even page).

PPPS. See my own anwer to get my success (or not) in this case.

    \documentclass{article}
\usepackage{graphicx}
\usepackage{amsthm}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{changepage}
\usepackage{xargs}
\usepackage{mwe}

\newcounter{pictnumber}
\renewcommand{\thepictnumber}{\arabic{pictnumber}}

\input{insbox.tex}
\usepackage{threeparttable}

\InsertBoxR{#3}{\begin{threeparttable}%
\begin{tabular}{c@{}}\includegraphics[width=#4\textwidth]{#2}\end{tabular}%
\captionof{figure}{}\end{threeparttable}}[#1]}

\begin{document}
\begin{proof}
\begin{enumerate}
\item
\lipsum[1]
\lipsum[2]
\item
\lipsum[3]
\end{enumerate}
\end{proof}
\newpage
\begin{proof}\leavevmode
\lipsum[5]
\end{proof}
\end{document}

• Wrapping text of various types around pictures is a frequent question here. The picins package uses \hangindent and wrapfig uses \parshape. Neither works with \item, but \rightskip will. It can be done, but sometimes you have to manually break paragraphs. – John Kormylo Mar 7 '16 at 2:50
• Sorry, but I only get equations when I try to run your code. See tex.stackexchange.com/questions/292780/… – John Kormylo Mar 7 '16 at 17:54
• @Dida, help people to help you by creating correct MWE: meta.tex.stackexchange.com/a/3225/79756 – Leonid Mar 9 '16 at 17:01
• regarding your question 5, an answer by heiko oberdiek tex.stackexchange.com/a/193105 solves the problem of the nasty spacing for theorems (proofs are quite like theorems in this respect), and also deals with the behavior of linking and labels; it does require hyperref. not an exact "drop in" solution, but might give you a starter. – barbara beeton Mar 9 '16 at 21:13
• Sorry, but I don't know anything about the Microsoft Word process of adding pictures so saying that you want something like this means as much to me as describing what you want in Chinese. Actually, less, because I could at least run Chinese through Google translate. It is years and years since I had to add a picture in Word. At that time, it was very far from being simple! – cfr Mar 12 '16 at 22:21

(It is anwer of me -- Author of this question -- keep it in mind)

The best solution is to take cup of tea and relax, I guess.

Btw, I've already founded solution to questions 1,2(only for right edge of page),3,5. By the way, I still need answers to the rest questions. AND, that's more important, I need advice to make simpler and better my own commands.

My solution is that not in lists it is better to use command \addpicture(see it below), and in list difficult way to use \wrappicture(see it below) is better.

# solution to question 1.

That's all in \wrappicture, exactly in \parbox

# BUT PEOPLE HELP ME. \WRAPPICTURE DOES NOT WORK ON THE LEFT SIDES OF PAGES.

btw, for right side it is in optional arguments of \wrappicture.

# solution to question 3.

I have solution, but it is very dirty and unprofessional, I guess. But it works.

\newcounter{pictnumber}
\renewcommand{\thepictnumber}{\arabic{pictnumber}}


And I should do \refstepcounter{pictnumber} in command \myaddpicture, because \label will see it, but will not see adding to counter in caption in macro for some reasons. This is works just because the number which indicated my counter is the same as the counter of figures. And after it I should do this adding to my own counter in every \begin{wrapfigure} (for example) to keep it the same. By the way, you can renewcommand caption to show my counter and do everything with my own counter.

# solution to question 5.

https://tex.stackexchange.com/a/299007/98432

And this is my final code now:

               \documentclass{book}
\usepackage{graphicx}
\usepackage{amsthm}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{changepage}
\usepackage{xargs}
\usepackage{mwe}
\usepackage{wrapfig}
\newcounter{pictnumber}
\renewcommand{\thepictnumber}{\arabic{pictnumber}}

\input{insbox.tex}
\usepackage{threeparttable}

\InsertBoxR{#3}{\begin{threeparttable}%
\begin{tabular}{c@{}}\includegraphics[width=#4\textwidth]{#2}\end{tabular}%
\captionof{figure}{}\end{threeparttable}}[#1]}

\InsertBoxL{#3}{\begin{threeparttable}%
\begin{tabular}{c@{}}\includegraphics[width=#4\textwidth]{#2}\end{tabular}%
\captionof{figure}{}\end{threeparttable}}[#1]}
\strictpagecheck%
\checkoddpage%
\ifoddpage
\else%
\fi%
}

\newcommandx{\wrappicture}[7][1=12,3=8,5=\mbox{},7=0]
{

\parbox[t]{\dimexpr\textwidth-\leftmargin}
{%
\vspace{-2.5mm}
\begin{wrapfigure}[#1]{o}{#4\textwidth}
\centering
\vspace{-\baselineskip}
\InsertBoxL{#7}
{\begin{threeparttable}%
\begin{tabular}{c@{}}\includegraphics[width=#4\textwidth]{#6}\end{tabular}%
\captionof{figure}{}\end{threeparttable}}
\end{wrapfigure}#2
\parbox[t]{\dimexpr\textwidth-\leftmargin}{%
\vspace{-2.5mm}
\begin{wrapfigure}[#3]{r}{#4\textwidth}
\end{wrapfigure}
#5 }
}
\refstepcounter{pictnumber}
}

\begin{document}
\refstepcounter{pictnumber}\refstepcounter{pictnumber}\refstepcounter{pictnumber}\refstepcounter{pictnumber}\refstepcounter{pictnumber}
\newpage
\begin{proof}\leavevmode
\begin{enumerate}
\item
\lipsum[1]
\wrappicture [9]{{\lipsum[2]  } }[0]{0.3}{example-image-a}

\wrappicture [0]{je\newline je\newline je\newline je\newline }[5]{0.3}[{{\item \lipsum[3]}}]{example-image-a}\label{i am seven}

\end{enumerate}
\end{proof}

\newpage
\begin{proof}\leavevmode