Cómo recrear el "ejercicio de curvatura peligrosa" en TeXbook con `amsthm`

Cómo recrear el "ejercicio de curvatura peligrosa" en TeXbook con `amsthm`

Estoy escribiendo un documento en este momento y tengo un warningentorno de teorema creado con amsthm. Lo que me intriga es que KnuthEl libro de textologró poner el símbolo de "curva peligrosa" frente a lo que parece ser un exerciseentorno. El símbolo abarca exactamente dos líneas, y el EXERCISEtexto en negrita y el siguiente se envuelven alrededor de ese símbolo, de modo que la tercera línea comienza y el margen izquierdo nuevamente.

Mi pregunta es si puedo recrear esto preferiblemente con amsthmentornos (modificados). Sé que trivlisten la implementación de los entornos causa problemas, pero es posible recrear el aspecto de amsthmlos entornos sin trivlist. Tenga en cuenta que la curva peligrosa llega incluso antes del encabezado (por ejemplo, página 5 deEl libro de texto).

Respuesta1

Bastante buen código en tu respuesta, pero se puede mejorar. En particular uso \clubpenaltiesen lugar de \clubpenalty, para que podamos

  1. desaconsejar un salto de página después de la segunda línea;
  2. no te preocupes por las palizas \clubpenalty;
  3. restablecer \clubpenaltiescon un gancho.

También escribí el encabezado.despuésel párrafo comienza, por lo que podemos usar \labely no preocuparnos por los espacios.

Para un aviso de una línea, examinamos \prevgrafal final del primer párrafo y, si es 1, se genera una línea vacía sin posible salto de página.

\documentclass{article}

\usepackage{manfnt} % for \dbend
\usepackage{lipsum} % for testing

\counterwithin{equation}{section}

\newlength{\dangerwidth} % width of \dbend
\settowidth{\dangerwidth}{\dbend}
\addtolength{\dangerwidth}{1em} % add any extra space between \dbend and text

\NewDocumentEnvironment{warning}{o}{%
  % I mostly use equation counter, feel free to use any other one
  % default \topsep before theorem environment
  \par\addvspace{\topsep}
  % no line break after first line and discourage after second line
  \clubpenalties=3 10000 5000 0 
  % after first paragraph, reset \clubpenalties
  \AddToHookNext{para/end}{\clubpenalties=0 }%
  % after first paragraph, count the number of lines, if one add an empty line and no page break
  \AddToHookNext{para/after}{\ifnum\prevgraf=1 \nopagebreak\hbox{}\fi}%
  % specifying indentation of first two lines
  \hangindent=\dangerwidth \hangafter=-2 
  % step the associated counter
  \refstepcounter{equation}%
  % store the start so to allow for \label
  \everypar\expandafter{%
    % remove the indentation box
    {\setbox0=\lastbox}% <----  !!!!!!!
    % zero width \dbend, shifted to left border
    \makebox[0pt]{\hspace*{-\hangindent}\dbend\hfill}%
    % theorem name and number
    \textbf{Warning \theequation}%
    % the attribution, if given
    \IfValueT{#1}{ (#1)}%
    % punctuation and space after
    \textbf{.}\hspace*{5pt plus 1pt minus 1pt}%
    % reset \everypar
    \everypar{}%
  }%
  % ignore spaces at the beginning
  \ignorespaces
}{
  % end the paragraph
  \par
  % default space after the environment
  \addvspace{\topsep}%
}

\begin{document}

\lipsum[66]

\begin{warning}[a note]\label{xyz}
    \lipsum[66]

    \lipsum[66]
\end{warning}

\begin{warning}
    \lipsum[66]
\end{warning}

\lipsum[66]

\begin{warning}
    One single line looks weird.
\end{warning}

Let's see the reference \ref{xyz}

\lipsum[66]

\end{document}

ingrese la descripción de la imagen aquí

Respuesta2

Después de muchos retoques, creo que tengo un resultado satisfactorio. Tomé los parámetros básicos de amsthmlos entornos y me inspiré en el de Knuth.El libro de textocódigo.

\documentclass{article}

\usepackage{manfnt} % for \dbend
\usepackage{lipsum} % for testing

\newlength{\dangerwidth} % width of \dbend
\settowidth{\dangerwidth}{\dbend}
\addtolength{\dangerwidth}{1em} % add any extra space between \dbend and text

\newenvironment{warning}[1][]{
    \begingroup % local definition
    \stepcounter{equation} % I mostly use equation counter, feel free to use any other one
    \par\addvspace{\topsep} % default \topsep before theorem environment
    \clubpenalty=10000 % no line break after first line
    \hangindent=\dangerwidth \hangafter=-2 % specifying indentation of first two lines
    \noindent\makebox[0pt]{\hspace*{-\hangindent}\dbend\hfill}% % zero width \dbend, shifted to left boarder
    \textbf{Warning \thesection.\theequation}% % theorem name and number
    \if\relax\detokenize{#1}\relax\else % optional argument, check if empty
        \space(#1)% % if so, type optional argument in parenthesis
    \fi
    \textbf{.}\hspace*{5pt plus 1pt minus 1pt}\ignorespaces % add default rubber after theorem header
}{
    \par\addvspace{\topsep}\endgroup % default \topsep after environment
}

\begin{document}

\lipsum[66]

\begin{warning}[a note]
    \lipsum[66]

    \lipsum[66]
\end{warning}

\begin{warning}
    \lipsum[66]
\end{warning}

\lipsum[66]

\begin{warning}
    One single line looks weird.
\end{warning}

\end{document}

ingrese la descripción de la imagen aquí

Tengo dos preguntas:

  1. A partir de ahora esto \clubpenalty=10000se aplica a todo el medio ambiente. ¿Puedo aplicarlo de alguna manera sólo al primer párrafo dentro de este entorno? EnEl libro de texto, Knuth no resolvió este problema ya que exigía que cada párrafo "peligroso" recibiera un símbolo de curvatura peligrosa.
  2. Como puedes ver enAdvertencia 0.3, una sola línea no se ve muy bien. ¿Hay alguna manera de remediar esto? Sugeriría que si solo hay una línea dentro warning, se podría usar \textdbenden lugar de \dbendcuyo pie y no su centro esté en la línea de base. ¿Cómo detecto esto?

No dude en enviar comentarios sobre cualquier cosa que falte en amsthmlos entornos originales o mejoras en el código anterior.

información relacionada