1

I was thinking that adding a \label{...} was not adding any space... But apparently it is wrong sometimes: for instance adding a \label{...} between two environments like proofs adds an unwanted space:

enter image description here

The problem is that I'm using this trick (maybe dirty, but can't find any other solution) in one of my package in order to obtain a reference to the current page/section... Any idea how to get rid of this unwanted space?

\documentclass{article}

\usepackage{amssymb, amsthm, amsmath}

\begin{document}

\section{Without unwanted space}

\begin{proof} Here is the space without any label after a proof \end{proof}

% \label{abc} %% <=== uncomment this line to see the space \begin{proof} Hello \end{proof}

\section{With unwanted space}

\begin{proof} Here is the space with a label after a proof \end{proof}

\label{abc} \begin{proof} Hello \end{proof}

\end{document}

tobiasBora
  • 8,684
  • Label needs to write to aux so leaves a whatsit. Why are you leaving a label there anyway? It isn't attached to anything. I would add it inside the proof. – daleif Jun 09 '21 at 13:58
  • Even a \null between two proofs adds space. \unskip after \end{proof} will fix it. – John Kormylo Jun 09 '21 at 14:05
  • @daleif - If his goal is to use \pageref instead of \ref, this will work. The page number isn't added until the page containing \protected@write is shipped, even if the corresponding \refstepcounter is on a different page. – John Kormylo Jun 09 '21 at 14:10
  • 1
    you can use this https://tex.stackexchange.com/a/600142/2388 here too. – Ulrike Fischer Jun 09 '21 at 14:25
  • The \label will end up in some essentially arbitrary position with no reference to anything, except the unknown page where it will eventually appear. So why bother? – egreg Jun 09 '21 at 15:33
  • @UlrikeFischer Thanks a lot, it works great! And thanks everybody for the help! – tobiasBora Jun 09 '21 at 19:03
  • @egreg Well right now I can use it to obtain the name of the current section since. I understand it's quite dirty, but I could not find a reliable proper way to do that differently. – tobiasBora Jun 09 '21 at 19:32
  • @tobiasBora Then \label should go just after or in the section title – egreg Jun 09 '21 at 19:40
  • @egreg My main issue is that I've no way to put the label right after the section title without asking my users (this is for a package I wrote) to write more code (I want to minimize the code typed by the user). The only solution I can imagine to do that would be to define two commands, one to put right after the beginning of the section, and one whenever the user wants to print the proofs... But then it increases the probability of doing an error since the user needs to maintain multiple codes. So far, it worked quite smoothly (at least when using cleveref)... Is it really that bad? – tobiasBora Jun 09 '21 at 19:46
  • @tobiasBora Redefine \section so that it updates a macro \currentsectiontitle. Please, make a fresh question with the details, so we can suggest better approaches. The best way to go is stating the real problem and not an attempted solution without clues to the actual problem to solve. – egreg Jun 09 '21 at 20:17
  • @egreg: the problem of redefining \section is that the code will depend on the "category" (at least I can't find how to avoid that issue, see the link below for more details). I did create a question a while ago here, see my "EDIT 2021" where I do explain precisely the problem/current poor solution I'm using. https://tex.stackexchange.com/questions/553394/reliably-add-a-label-to-the-current-section-even-if-the-label-is-not-placed-rig – tobiasBora Jun 10 '21 at 11:36

0 Answers0