6

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.

zero. How to set default value of optional argument exactly in function?

  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:

enter image description here

  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:

enter image description here

  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:

enter image description here

the fourth:

enter image description here

  1. How to find the right number of lines?

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[colorlinks]{hyperref}
    \usepackage{xargs}
    \usepackage{mwe}

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

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

\newcommandx\myaddpicture[4][1=5,3=0]{\refstepcounter{pictnumber}%
\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]
    \addpicture{example-image-a}{0.3}
    \lipsum[2]
    \addpicture{example-image-a}{0.3}
    \item
    \lipsum[3]
\end{enumerate}
\end{proof}
  \newpage
  \begin{proof}\leavevmode
  \addpicture{example-image-a}[2]{0.45}
  \lipsum[5]
  \end{proof}
\end{document}   
  • 1
    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 07 '16 at 02:50
  • @JohnKormylo I know that it is frequent, but I can't find answer on my own question. That's why I asked it...

    Can you help with \rightskip? My first attempts were very bad.

    –  Mar 07 '16 at 07:31
  • 1
    Sorry, but I only get equations when I try to run your code. See http://tex.stackexchange.com/questions/292780/a-list-and-a-figure-side-by-side/292794?s=3|0.0580#292794 – John Kormylo Mar 07 '16 at 17:54
  • You will get the same results shown at printscreen, if you will use english words or lipsum.

    I use \rightskip with success in each case.

    Your variant is kind of manual work. I have hundreds of pictures. And I have manual macroses, that consume all my wishes, but I am sure with power of LaTeX it is possible to do that automatically.

    –  Mar 07 '16 at 18:06
  • 3
    @Dida, help people to help you by creating correct MWE: http://meta.tex.stackexchange.com/a/3225/79756 – Leonid Mar 09 '16 at 17:01
  • @Leonid, thanks for advice, I thought about readability and lipsum, when I was writting this question. But when I try to solve this, I meet many problems with formulas and their huge number in my book, so I decided not to use lipsum.

    But if you wish, I did it. Take a look.

    –  Mar 09 '16 at 18:10
  • @Dida, would be great to have easy working copypastable code. No downloading from other resources - just copy and paste. "! LaTeX Error: File `rtr2' not found." - copypasting and running with pdflatex gives such error.After this one can try to play around with code in search for solution. Remember to show your 5 problems in this example – Leonid Mar 09 '16 at 18:22
  • @Leonid, are you talking about option demo? Well, I will use it too, but again I was thinking about it -- if you see a black square, you will not see text overlay in its full manifestation... Oh, but you are right about "just copy and paste". I will take that into account. –  Mar 09 '16 at 18:32
  • @Dida, demo option, filecontents package - whatever you have to do to present working copypastable example of problems of minimum size (in your case it probably should compile to three pages to be able to test even and odd pages). – Leonid Mar 09 '16 at 18:40
  • @Leonid, thanks a bunch, I will be more attentive next time. –  Mar 09 '16 at 18:49
  • 1
    regarding your question 5, an answer by heiko oberdiek http://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 09 '16 at 21:13
  • 1
    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
  • You can use the images provided by the mwe package if black boxes make it difficult to see the problem. \includegraphics{example-image-a} will work on any system with a standard installation of TeX. – cfr Mar 12 '16 at 22:24
  • To those asking about insbox.tex: it is part of standard TeX distributions, just as threeparttable.sty is and should be equally unproblematic. (The .tex extension should be unneeded, of course, but won't stop it working.) – cfr Mar 12 '16 at 22:26
  • @cfr thanks for your advice. I mean "very simple", In Word's latest versions it can be done just in a few clicks.

    I am sure that with power of LaTeX it can be solved.

    –  Mar 12 '16 at 22:58

1 Answers1

1

(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

enter image description here

solution to question 2.

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

enter image description here

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

enter image description here

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.

enter image description here

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}    
\usepackage[colorlinks]{hyperref}
\newcounter{pictnumber}
\renewcommand{\thepictnumber}{\arabic{pictnumber}}  



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

\newcommandx\addpictureR[4][1=5,3=0]{\refstepcounter{pictnumber}%
\InsertBoxR{#3}{\begin{threeparttable}%
\begin{tabular}{c@{}}\includegraphics[width=#4\textwidth]{#2}\end{tabular}%
\captionof{figure}{}\end{threeparttable}}[#1]}

\newcommandx\addpictureL[4][1=5,3=0]{\refstepcounter{pictnumber}%
\InsertBoxL{#3}{\begin{threeparttable}%
\begin{tabular}{c@{}}\includegraphics[width=#4\textwidth]{#2}\end{tabular}%
\captionof{figure}{}\end{threeparttable}}[#1]}
\newcommandx{\addpicture}[4][1=5,3=0]{%
\strictpagecheck%
\checkoddpage%
\ifoddpage
\addpictureR[#1]{#2}[#3]{#4}
\else%
\addpictureL[#1]{#2}[#3]{#4}
\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
  \addpicture{example-image-a}[1]{0.45}
  \lipsum[5]
  \end{proof}

   \newpage

hello \ref{i am seven}

\end{document}  
  • May be it is better to ask about problem with left sides separatly? –  Mar 14 '16 at 17:58