0

I have the following environment for using \dotfill in a cases environment

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}

\setlength{\parindent}{0pt}

\makeatletter

\newenvironment{DotCases}[1]{%  
    {#1}
\@ifdefinable\@FunFill{\newdimen\@FunFill}
\settowidth\@FunFill{$#1\left\{ \right.\kern -\nulldelimiterspace$}
    \left\{%
    \tabcolsep \z@
    \def\arraystretch{1.2}
    \tabularx{\dimexpr \linewidth-\@FunFill-2pt \relax}%
                {>{$}r<{$}>{${}}X<{$}}%
}{%
    \endtabularx
    \right.%
    \kern -\nulldelimiterspace
}

\makeatother

\begin{document}

$
\begin{DotCases}{f(x) = }
& x   \dotfill \text{text}\\
& 1-x \dotfill \text{more text}
\end{DotCases}
$

$
\begin{DotCases}{f(x) = }
& x   \dotfill \text{text}\\
& 1-x \dotfill \text{more text}
\end{DotCases}
$

\end{document}

I have compiled solutions from various places, and I only partially understand what's going on. What I am trying is to keep everything within linewidth and thus subtracting the width of #1 and the left bracket from the \dotfill command - well sort of, because I have to subtract around 2pt extra to ensure vertical alignment.

Writing a single DotCases environment works fine, but writing multiple DotCases gives the error \@FunFill already defined. Any suggestions for how to solve this?

2
  • 1
    don't post disconnected fragments that are hard to debug, post a small complete document that shows the error. but ever do \newdimen\@FunFill} inside a document environment, you do not want to allocate a new register each time, just do this once ehen the macros are defined. Commented Nov 18, 2023 at 20:17
  • I have edited the post to only include one complete code fragment. Thanks for pointing it out. I am not sure how to implement your suggestion, can you please elaborate, preferably with the complete code snippet? Thanks!
    – DavidH
    Commented Nov 18, 2023 at 20:40

1 Answer 1

2

Never allocate registers in document environments, they are a fixed resource you just want to allocate them once, as the code is loaded.

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}

\setlength{\parindent}{0pt}

\makeatletter

\newdimen\@FunFill

\newenvironment{DotCases}[1]{%  
    {#1}%%%%%%
\settowidth\@FunFill{$#1\left\{ \right.\kern -\nulldelimiterspace$}%%%%%%%
    \left\{%
    \tabcolsep \z@
    \def\arraystretch{1.2}
    \tabularx{\dimexpr \linewidth-\@FunFill-2pt \relax}%
                {>{$}r<{$}>{${}}X<{$}}%
}{%
    \endtabularx
    \right.%
    \kern -\nulldelimiterspace
}

\makeatother

\begin{document}

$
\begin{DotCases}{f(x) = }
& x   \dotfill \text{text}\\
& 1-x \dotfill \text{more text}
\end{DotCases}
$

$
\begin{DotCases}{f(x) = }
& x   \dotfill \text{text}\\
& 1-x \dotfill \text{more text}
\end{DotCases}
$

\end{document}

You must log in to answer this question.

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