0

I'm using a little macro found on Stack Exchange to define a vertically centered dotfill, but I don't understand it at all and it feels like an "hack" to me. Is there other ways in writing this macro without the \makeatletter and \makeatother, and without the @, using {} for example? Is there other ways in achieving a similar result (i.e to get mid-line centered \dotfill)? Here's a MWE showing the effect:

\RequirePackage[l2tabu,orthodox]{nag}
\documentclass[11pt,twoside,draft]{book}
\usepackage[T1]{fontenc}
\usepackage[nomath]{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype,textcomp}
\usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}

\makeatletter \newcommand{\cdotfill}{\leavevmode\cleaders\hb@xt@.44em{\hss$\cdot$\hss}\hfill\kern\z@} \makeatother

\begin{document}

\mainmatter \pagestyle{plain}

\chapter{A first chapter}

\section{A section title}

Blablabla blabla bla.

\dotfill

Blablabla blabla bla.

\cdotfill

Blablabla blabla bla.

\end{document}

Preview:

enter image description here

Cham
  • 2,304
  • 1
    what's wrong with that definition, it's almost identical to the standard \dotfill if you don't want @ replace \hb@xt@ by \hbox to which is three tokens rather than one, so saves a couple of bytes but the chance you need those bytes saved in 2003 is small. and similarly replace \z@ by 0pt – David Carlisle Jul 10 '23 at 13:51
  • https://tex.stackexchange.com/a/55401/1090 – David Carlisle Jul 10 '23 at 13:58
  • @DavidCarlisle, so this is a bit better understandable to me: \newcommand{\cdotfill}{\leavevmode\cleaders\hbox to 0.44em{\hss$\cdot$\hss}\hfill\kern0pt}. What about the \makeatletter and \makeatother ? It's weird to me to have these on top and below a \newcommand. – Cham Jul 10 '23 at 14:03
  • you just need those to access command names that use @ they read as "make @ letter" and "make @ other" so if you are not using @ you don't need them – David Carlisle Jul 10 '23 at 14:05
  • that use is not weird though, the only purpose of those commands is to allow package code (which can use @) in the preamble for short fragments so they are almost always used around definitions such as this if they are used at all. – David Carlisle Jul 10 '23 at 14:07
  • @DavidCarlisle, ahaa! Got it. Now the macro is already much simpler (to me). So removed all the @ and the lines on top and below. It's already looking more like the "normal" macros I use : \newcommand{\cdotfill}{\leavevmode\cleaders\hbox to 0.44em{\hss$\cdot$\hss}\hfill\kern0pt}. So is that one right? – Cham Jul 10 '23 at 14:09
  • 1
    yes, note which is "simpler" depends on what you are doing, if you just look at the definition your version is more readable, but if you want to compare with \dotfill to see what changed, the original version which just changes . to $\cdot$ and keeps the rest the same makes it easier to highlight the change. – David Carlisle Jul 10 '23 at 14:11
  • @DavidCarlisle, I'm a bit surprised that there isn't any \cdotfill already defined for the text mode. Maybe this is a separate question: the current cdotfill macro doesn't seem to center the dot exactly at the center bellow text lines. Is there a better way in getting a vertically centered dot, between two lines of text? – Cham Jul 10 '23 at 14:15
  • defining vertical centre is tricky, your example might suggest there is more space above but add some yyyyy to the text: your macro does not adjust to the surrounding text it just makes a row of cdot which are on the math axis rather than the base line, exactly as if you had a row of +++++ which are also centred on the math axis – David Carlisle Jul 10 '23 at 14:18
  • @DavidCarlisle, I understand that. Is there a way to get a better centered dot in text mode? Can you suggest a macro? I suspect that it would be very difficult... – Cham Jul 10 '23 at 14:25
  • as I say you need to define what you mean by centering, it will look odd if you change the spacing depending on the surrounding text. cdot is probably as good as anything unless you are using a script that never has descenders, when you probably want something a bit higher – David Carlisle Jul 10 '23 at 14:31
  • @DavidCarlisle, the cdotfill is to be used only between two items in a very long list. Each item in the list is a paragraph, and the dotfill makes the items to be more easily readable and searchable. The centered cdotfill is just for the aesthetics. It's nicer to get well centered dotted lines between each paragraph in the list. – Cham Jul 10 '23 at 14:36

0 Answers0