I want a command \shybar which prints a \textbar except if it would be the first character on the page. In this case, it should do nothing. Because of this question, I tried the following code:



\shybar This bar should not be printed, but \shybar this one should.

I inserted an \mbox because \leaders asked for a box. Anyway, it did not work; it still asks for boxes. How can I solve this problem?

  • 1
    There is no concept for the first character on a page. As far as typesetting paragraphs is concerned, you should imagine them printed on a a long scroll of paper, so there's no way (at least with standard TeX) to have \shybar to disappear if it is inside a paragraph and it happens to be the first item on the first line on a new page: paragraphs are typeset before page break decision are made.
    – egreg
    Jul 24, 2014 at 12:59
  • Well, too bad then... :-)
    – Gaussler
    Jul 24, 2014 at 13:04
  • Maybe something can be done with LuaTeX. Can you tell why you'd like to do this?
    – egreg
    Jul 24, 2014 at 13:08
  • you CAN tell if a character is the first in a paragraph using \ifvmode. Jul 24, 2014 at 16:07
  • 1
    I tried to use atbegshi and tikzpagenodes to delay drawing the \textbars until \AtBeginShipout, but the bars got drawn on the next page. Interestingly, they showed up in the right spots. Jul 24, 2014 at 22:56

1 Answer 1


It occurred to me that \tikz[remember page,overlay] must already wait until the page is laid out in order to work right. Nor will it change the layout since it overlays the existing text.



\newcommand*\shybar{\ifvmode\tikz[remember picture,overlay]% start of paragraph
{\pgfextracty{\tempy}{\pgfpointdiff{\pgfpointorigin}{\pgfpointanchor{current page text area}{north west}}}%
\else\tikz[remember picture,overlay]% inside paragraph
{\let\p1=\pgfpointdiff{\pgfpointorigin}{\pgfpointanchor{current page text area}{north west}}%
\ifdim\tempy<\baselineskip \ifdim\tempx=0pt \relax%
\hspace*{1pt}}% reserve space

\shybar This bar should not be printed, but \shybar this one should.


Last line of page\newline
\shybar This bar should not be printed, but \shybar this one should.

This approach has a problem with things like hanging indentation.


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.