1

I am a professor and I usually prepare lists of exercises using the LibreOffice. For years, I faced problems like loosing the sequence of question number after adding new problems to the list (just to cite an example).

This year I bagan gathering the questions in a TEX file. Of course I tried many packages like answers, exsheets, and probsoln. They have good features, but none of them could allow me to wrap the exercises text around their related figures.

After spending pretty much time (I am new LaTeX user), I got nice results by creating a very simple class, but still face some issues. The image below shows the issues I still face.

This is how my list of exercises looks like. The green arrows and comments are the desired features I accomplished by creating the <code>problems</code> class. In read, I point some issues I still face.

As can be seen in the image 1, I face the following problem: sometimes, one figure is higher than the exercise's text, forcing the next exercise's text to wrap arround (... arround nothing reamaining from past figure). Or worse! As can be seen in my note on the image 1, Q 1.4 should have it's own figure, which was suppressed by the extent of the previous figure. I know that I could handle it by inserting some \\, but I would like to have the comfort of LaTeX automatically handling it for me when I begin to deal with much more exercises. I mean, for the cases wher the figures are higher than their related exercise's text, I would like to know a way of commanding LaTeX to measure the remaining space occupied by it and force the next exercise's paragraph begin after that space.

I wouldn't like to use any package that do not support text wrapping figures. I would like to solve this issue adding some features to the problems class, if possible.

Code of my problems.cls:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-------------------------- PACKAGES CALL ---------------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\LoadClass[10pt]{article}
%... Loads all the commands and styles defined in article class.

\NeedsTeXFormat{LaTeX2e}
%... Tells the compiler which version of LaTeX the package is for.

\pagenumbering{gobble}
%... suppresses page numbering.

\ProvidesClass{problems}[2018/06/19 by Joaquim Brasil]
%... gives the compiler some info about this package.

%-> The titlesec package provides the command \titleformat which lets us customize our section headings.
\RequirePackage{titlesec}
    \titleformat{\section}[block]{\Large\bfseries\filcenter}{}{1em}{}
    %... I used \titleformat here to center the section title

\RequirePackage[utf8]{inputenc} %-> accepts Latin accentuation

\RequirePackage{isomath}
%... provides tools for a mathematical style that conforms to the International Standard ISO 

\RequirePackage{amsmath}
%... provides a handful of options for displaying equations (especially: multiline)

\RequirePackage{bbm}
%... blackboard variants of Computer Modern fonts

\RequirePackage[sc]{mathpazo}
%... a family of PostScript fonts suitable for typesetting mathematics in combination with the Palatino family of text fonts (especially: boldface math symbols)

\RequirePackage{fouriernc}
%... sets up NC Schoolbook, from the fourier package, as the front for the main text with a suitable font for math

\RequirePackage[T1]{fontenc}
%... allows the user to select font encodings, and for each encoding provides an interface to ‘font-encoding-specific’ commands for each font. Its most powerful effect is to enable hyphenation to operate on texts containing any character in the font

\RequirePackage{microtype}
%... provides a LATEX interface to the micro-typographic extensions

%-> Defining the paper size, margin widths, and borders:
\RequirePackage[a4paper,
                left=10mm, top=10mm, right=10mm, bottom=10mm,
                headheight=0mm, footskip=0mm, marginparsep=0mm, headsep=0mm,
                showframe]{geometry}

\setlength{\parindent}{0pt}
%... vanishes indentation

\RequirePackage[all]{nowidow}
%... prevents paragraph breaking into next page

\RequirePackage{nameref}
%... defines a \nameref command, that makes reference to an object by its name (e.g., the title of a section or chapter). It is part of the hyperref bundle, and works well with hyperref

%-> Packages for image floats:
\RequirePackage{graphicx, wrapfig}
    \graphicspath{ {1_Mechanics/_images/} }
        %... sets the folder source of images
    \setlength{\intextsep}{0cm}
        %... sets the vertical margins of the figure

%-> Package for font (and other elements) color:
\RequirePackage{color}
    \definecolor{Gray}{gray}{0.5}

%-> Packge for column setting:
\RequirePackage{multicol}






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------------- BASIC HEAD DEFINITIONS ----------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-> Defining the DISCIPLINE NAME command:
\def\discipline#1{\def\@discipline{#1}}
    \newcommand{\dname}{\@discipline}

%-> Defining the LIST NUMBER command:
\def\listnumber#1{\def\@listnumber{#1}}
    \newcommand{\lnum}{\@listnumber}

%-> Defining the LIST TITLE command:
\def\listtitle#1{\def\@listtitle{#1}}
    \newcommand{\ltitle}{\@listtitle}

%-> Defining the PROFESSOR'S NAME command:
\def\myname#1{\def\@myname{#1}}
    \newcommand{\me}{\@myname}

%-> Defining the LIST HEADER command:
\def\makeheader{%
    \centerline{\large\dname\ -- \lnum\textordfeminine\ LISTA DE EXERCÍCIOS -- \ltitle}%
    \vspace{5mm}
    }






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------------- ENVIRONMENT DEFINITIONS ---------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%-> The INFORMATION environment is an area in the exercise list reserved to supplement info necessary for solving the problems.
%-> Defining the INFORMATION environment:
\newenvironment{info}[1]
    {%
    \noindent{\bf#1}
    \small
    \color{Gray}
    \vspace{2mm}
    }{\bigskip}

%-> Defining COUNTERS:
\newcounter{problem}[section] %-> counter is reset at new section
\newcounter{letter}[problem] %-> counter is reset at new problem

%-> Defining the numbered environment for EXERCISES:
\newcommand{\problem}[2]{%
    \refstepcounter{problem}\bigskip\paragraph{%
    \textbf{#1 \lnum.\theproblem- [#2]}}\rmfamily}{\bigskip\par}

%-> Defining the EXERCISE'S LETTER counter:
\def\ltt{\textbf{(\stepcounter{letter}\alph{letter})\ }}

%-> Defining the reference for problem author:
\newcommand{\auth}[1]{%
    {\footnotesize [#1]}%
    }

%-> Defining the environment for the FIGURES:
\newcommand{\theimage}[2]{%
    \begin{wrapfigure}[]{r}{#2\textwidth}%
        \includegraphics[width=#2\textwidth]{#1}
    \end{wrapfigure}%
}

%-> Defining the environment for the ANSWERS PAGE:
\newenvironment{answers}{%
    \newpage
    \begin{center} \textbf{RESPOSTAS DA LISTA \lnum\ -- \ltitle} \end{center}
    }

%-> Each exercise has is identified by its name (despite of its number). The answer is referred to the exercise's name.
%-> Defining the command for the ANSWERS TITLE
\newcommand{\Name}[1]{%
    \par\medskip
    \footnotesize \textbf{[#1]}:
    }{\medskip}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------------- ADDITIONAL DEFINITIONS ----------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\deg{\textdegree}

Code of one sample of exercise list:

\documentclass{problems}

\discipline{FÍSICA 1}
\listnumber{1}
\listtitle{\textbf{T}ÓPICOS DE \textbf{T}RIGONOMETRIA E \textbf{P}ROPORÇÕES}
\myname{Prof. Joaquim}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----- BEGIN DOCUMENT -------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\makeheader

\problem{Q}{Percurso acessível}
Para cada desnível máximo de seguimento de rampa previsto pela ABNT NBR 9050 de 2015, calcule \ltt o valor $c$ de sua projeção horizontal e \ltt o valor $r$ de percurso na rampa (hipotenusa) para as inclinações mínimas e máximas.
\auth{\me}



    \begin{wrapfigure}{r}{0.15\textwidth}
        \includegraphics[width=0.15\textwidth]{medidaindireta.png}
    \end{wrapfigure}
%
\problem{Q}{Medida indireta}
Em sua campanha eleitoral, o prefeito de uma cidade prometeu construir uma ponte para melhorar o deslocamento dos moradores de um bairro ao centro e outras localidades. Depois de eleito, chegou a hora de cumprir a promessa, e você é o engenheiro da empresa contratada por licitação que vai fazer parte da equipe que trabalhará no projeto. Sua missão: calcular a largura $l$ do rio. Mas você só tem uma trena de comprimento máximo $L$ = 20,00 m. Além disso, não tem como atravessar o rio naquela região onde a ponte será construída. Você então percebe que há uma árvore ali bem próxima à margem oposta à qual você se encontra. Daí, você finca uma estaca no ponto A a partir de onde você começa a esticar sua trena e caminha até um ponto B onde você (usando um transferidor) observa que a árvore forma um ângulo reto com a estaca A, verificando que ali a trena marca $d$ = 20,00 m. Em seguida, você volta à estaca A e verifica que a árvore forma um ângulo 82° $\leq \theta \leq$ 83° com a estaca B. Calcule a largura do rio.
\auth{\me}




    \begin{wrapfigure}{r}{0.15\textwidth}
        \includegraphics[width=0.15\textwidth]{doisangulos.png}
        \vspace{-\normalbaselineskip}
    \end{wrapfigure}
%
\problem{Q}{Dois ângulos}
A vida não é feita de perfeição e por isso nem sempre você garante uma triangulação reta. Mas isso não lhe impede de cumprir sua missão em determinar a largura de um rio. Para isso, você estica sua trena de modo que seus extremos A e B se situem de lados opostos da projeção do ponto C da árvore à sua margem. Mirando o ponto C, você mede os ângulos 85,0\deg\ $\leq \alpha \leq$ 86,0\deg\ e 86,0\deg\ $\leq \beta \leq$ 87,0\deg. Sendo $d$ = 20,00 m, calcule a largura $l$ do rio.
\auth{\me}




    \begin{wrapfigure}{r}{0.25\textwidth}
        \includegraphics[width=0.25\textwidth]{indiretaalternativa.png}
        \vspace{-\normalbaselineskip}
    \end{wrapfigure}
%
\problem{Q}{Indireta alternativa}
Para se certificar da medida feita (exercício anterior), você fincou uma estaca A de 1,80 m de altura na margem do rio e depois, de carro, atravessou a única ponte da cidade (distante dali) e se deslocou até a outra margem e fincou a estaca B, também de 1,80 m bem à frente da estaca A e verificou que 0,6\deg\ $\leq \theta \leq$ 0,7\deg. Calcule dessa vez o valor da largura l do rio.
\auth{\me}




%-----> BEGIN THE CHALLENGES <-----%
\section*{***}


    \begin{wrapfigure}{r}{0.25\textwidth}
        \includegraphics[width=0.25\textwidth]{segundosol.png}
    \end{wrapfigure}
%
\problem{D}{Segundo Sol} Certa vez lendo um livro aprendi que é possível estimar o valor do raio da Terra observando o pôr do Sol. O texto do livro dizia:
%
\textit{\small Você está deitado na praia e vê o sol se pôr no mar. Levantando-se, vê o sol se pôr uma segunda vez. Acredite ou não, a medição do intervalo de tempo entre os dois crepúsculos permite estimar o raio da Terra.} {\small [D. Halliday, R. Resnick, J. Walker. \textbf{Fundamentos de Física.} 4ed, v1.]}
%
Já tive várias oportunidades de realizar esta medida e, para isto, até criei um instrumento específico que consiste em uma vara mais ou menos da minha altura à qual fiz dois furos distantes $h$ = 160 cm entre si. Fincada na areia, observo o primeiro pôr do Sol por meio do furo inferior, convenientemente feito a 15 cm acima do chão. Ao fim do pôr do sol, inicio a contagem do tempo acionando um cronômetro e imediatamente me levanto para observar o fim do segundo pôr do sol por meio do furo superior. Das observações que fiz o intervalo de tempo sempre esteve no intervalo 9,5 s $\leq \Delta t \leq$ 10,0 s. Calcule o valor para o raio da Terra.
\auth{\me}






\end{document}

The images I use in the exercises:

indiretaalternativa.png doisangulos.png medidaindireta.png segundosol.png

That's it. I hope someone can help me. Thank you very much!

  • 3
    Welcome to TeX.se. Unfortunately, this site works best if we keep things to one question per post. Would you be able to trim this down to one question, and have your other questions on related posts? That should also let you trim your code down to a manageable 20 lines or so, which would let you post the code in the question itself. – Teepeemm Jun 22 '18 at 0:52
  • 1
    I agree with Teepeemm that it would be better to ask several small questions than one big question, see also tex.meta.stackexchange.com/q/7425/35864. The link to your project asks me for a login (which I don't have), so I can't look at the code. Please always post small code examples (so called MWEs, see I've just been asked to write a minimal example, what is that?) that we can compile without further ado, just after copying and pasting (so please use surrogate packages like mwe ... – moewe Jun 22 '18 at 6:34
  • 1
    ... or duckuments) as code directly in your question on this site, so your question is self-contained. People shouldn't have to chase down your code on some other site (behind a log-in or paywall) and should not have to download stuff off shady file sharing pages. – moewe Jun 22 '18 at 6:35
  • 1
    Put \bigskip\par rather than just \bigskip at the ends of the environments. Off-topic: \bf etc. are several decades obsolete and ought not be used in LaTeX. They also don't take arguments. And you are introducing spurious spaces by failing to comment line endings. Never use \\ to end a line outside special environments, such as tabular or array. – cfr Jun 23 '18 at 0:46
  • 1
    \large etc. doesn't take an argument either. What is the point of the \lnum etc. commands? These seem needlessly complicated. Do you really need \def rather than \newcommand? Never use the former if you can help it. (Unless you really, really want to. Enough to accept the consequences.) – cfr Jun 23 '18 at 0:53
1

I didn't read the whole class i the OP, but I have a likely to brutal but unbreakable workaround, that I systematically use, replacing the very fragile ```wrapfigure` by nested minipages like this :

\begin{minipage}{\textwidth}
   \begin{minipage}{0.8\textwidth}
    text of question...
   \end{minipage}%
   \begin{minipage}{0.2\textwidth}\flushright
     \includegraphics[width=0.9\linewidth]{...}
   \end{minipage}
\end{minipage}
  • Thank you @jhor. The problem with your workaround is that it will make my job become much more manual, causing me to pay quite the same effort as I already pay using LibreOffice. :/ – Brasil Jun 23 '18 at 22:02
  • 1) I am sure that this scheme could be implemented to make it as easy as your present problematic wrapfig solution. 2) wrapfig is known to have some flaws and is mostly considered as obsolete and to be replaced by floatflt. 3) I unsuccessfully tried to compile the code you posted. There is a big problem in \problem : the definition uses a parameter #3 while the macro is declared with 2. Beside this, the images are renamed by TeX.SX with random names and therefore can't be found by pdfLaTeX. 4) It could be a good idea to explicitly declare the input encoding... – Jhor Jun 24 '18 at 12:59
  • Hi, @Johr. You're wright. I misdefined the \problem adding an extra parameter that I don't call. I just corrected the definitions in the problem.cls file. But it doesn't solve my problem. I will try the \floatfltyou suggest and tell you if it works. Thank you very much :) – Brasil Jun 24 '18 at 15:25
  • Of course, it can not fx the problem. But If has a compilable set of files, I could help you to implement the workaround in an easy way of use – Jhor Jun 24 '18 at 17:33
  • Hi, @Johr. I marked your answer as a correct answer. It is not the one I sought, but it works. Even though, as I already remarked, I will not use it because it will meke me do the effort I dont' want to. Instead, I will keep using the add-line command \\ , which brings me less work. Any way, I thank you very much for the help. I hope someone else provide additional answers that suits better this problem. Good work, guys! – Brasil Jun 25 '18 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.