2

I want to be able to make \dotfill in math \begin{align*} mode

Here is my code

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align*}
& M=E-e \sin E \makebox[5cm]{\dotfill} \tag{1}\\
& A=B+C
\end{align*}

\end{document}

But this does not work. I want the dots to go up to the tag (1) as in old typography. I also want that the dots do not move the equation. I want also the dots to fill automatically the space until the tag. Thanks for any help

Update 29/10/2022

I have now a macro that allows to just set the length of the dot sequence. But I would like to do it in an automated way.

\newcommand{\jdot}[1]{ \rlap{\makebox[#1]{\dotfill} }}

Now my LateX code becomes

\documentclass{article}
\usepackage{amsmath}
\newcommand{\jdot}[1]{ \rlap{\makebox[#1]{\dotfill} }}
\begin{document}

\begin{align*}
 M&=E-e \sin E \jdot{4.4cm} \tag{1}\\
 A&=B+C
\end{align*}

\end{document}

The dot sequence do not move the equation, thanks to the rlap but I still need to define manually the length of the sequence. The challenge is to find this length in an automated way.

1 Answer 1

1

I have learned a solution from the CTeX-org forum. After a few modifications, the code is as follows:

\documentclass{article}
\usepackage{amsmath}
\usepackage{zref-savepos}

\makeatletter
\ExplSyntaxOn

\zref@require@unique

\NewDocumentCommand { \dotstag } { O{} m }
  {
    \mode_if_math:TF
      { \@@_math_cdotfill:n { (#2) } }
      { \__examzh_cdotfill: (#2) }
    \mode_if_math:F
      {
        \par \noindent \ignorespaces
      }
  }
% 仿照 latex.ltx, line 651 的 \dotfill
\cs_new:Npn \__examzh_cdotfill:
  {
    \mode_leave_vertical:
    \cleaders \hb@xt@ .44em {\hss $\cdot$ \hss} \hfill
    \kern\z@
  }

\cs_new_protected:Npn \@@_math_cdotfill:n #1
  {
    \stepcounter { zref@unique }
    \hbox_overlap_right:n
      {
        \zsaveposx { \thezref@unique L }
        \zref@ifrefundefined { \thezref@unique R }
          { }
          {
            \cleaders
              \hbox_to_wd:nn { .44em } { \hss $\cdot$ \hss }
              \skip_horizontal:n
                {
                    \zposx { \thezref@unique R } sp
                  - \zposx { \thezref@unique L } sp
                }
          }
      }
    \tag * { \zsaveposx { \thezref@unique R } #1 }
  }

\ExplSyntaxOff
\makeatother

\begin{document}

Test with \verb|\dotstag{}|:
\begin{align*}
    M & = E - e \sin E \dotstag{1} \\
    A & = B + C \dotstag{2}
\end{align*}

\end{document}

Note that you should compile twice to get the desired result. By the way, the \dotstag command can also be used in the text mode!

enter image description here

3
  • This is great Stephen !!
    – Jacques
    Commented Oct 29, 2022 at 15:29
  • This is great Stephen !! Exactly what I needed. At first I thought it did not work. Then I read that one needs to compile twice. The first time you dont have the dots. The second time everything is in place. I must say I am not sufficiently expert in TeX to understand the code. Its quite complicated. We will see if someone comes with something simpler, but meanwhile, it fulfils entirely the requirement. Thanks again.
    – Jacques
    Commented Oct 29, 2022 at 15:35
  • @Jacques Glad that this method helps. And I am looking forward to more interesting solutions for this problem.
    – Stephen
    Commented Oct 29, 2022 at 16:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .