
Estoy intentando escribir un guión em ---
dentro de un alltt
entorno, pero obtengo tres guiones en lugar de un solo guión.
MWE
\documentclass[12pt]{article}
\usepackage{alltt}
\begin{document}
Usually, \verb"---" becomes an em dash, i.e. "---", in normal mode.
But in the alltt environment, it becomes three hyphens.
\begin{alltt}
Please---will you give me an em dash?
\end{alltt}
\end{document}
Respuesta a comentarios Los comentarios preguntaban por qué quiero escribir un guión em en un entorno monoespaciado. Me gustaría componer un guión que parezca un guión largo, pero que tenga la longitud de dos espacios en un entorno monoespaciado, es decir, como "--" pero unidos para formar un solo carácter similar a un guión largo.
Respuesta1
Mi sugerencia sería "ocultarlo" en forma de macro de donde se tomó el em-dash \normalfont
:
\documentclass{article}
\newcommand{\emdash}{{\normalfont ---}}
\usepackage{alltt}
\begin{document}
Usually, \verb"---" becomes an em dash, i.e. ``---'', in normal mode.
But in the alltt environment, it becomes three hyphens.
\begin{alltt}
Please\emdash{}will you give me an em dash?
\end{alltt}
\end{document}
A menos que la fuente monoespaciada venga con un guión largo, se establecerá como guiones separados. Podrías forzar un tablero em de aspecto monoespaciado, tal vez con una definición \emdash
similar a:
\documentclass{article}
\makeatletter
\newlength{\emdashttlen}
\settowidth{\emdashttlen}{\ttfamily---}
\newcommand{\emdash}{\makebox[\emdashttlen]{-\cleaders\hbox{\hspace{-.45ex}-}\hfill\kern0pt}}
\makeatother
\usepackage{alltt}
\begin{document}
Usually, \verb"---" becomes an em dash, i.e. ``---'', in normal mode.
But in the alltt environment, it becomes three hyphens.
\begin{alltt}
Please---will you give me an em dash?
Please\emdash{}will you give me an em dash?
\end{alltt}
\end{document}
Alguna información sobre los líderes se puede encontrar enQuiere llenar la línea con una cadena repetida.
Respuesta2
Solución simple: use UTF-8
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{alltt,etoolbox}
\apptocmd{\alltt}{\def\textemdash{{\fontfamily{cmvtt}\selectfont---}}}{}{}
\begin{document}
\begin{alltt}
Please—will you give me an em dash?
Please--will you give me an em dash?
\end{alltt}
\end{document}
Tenga en cuenta que la primera línea contiene — (Unicode U+2014 EM DASH)
Solución más complicada: transformarse ---
en{\fontfamily{cmvtt}\selectfont---}
\documentclass{article}
\usepackage{alltt,etoolbox}
\makeatletter
\begingroup\lccode`~=`-
\lowercase{\endgroup\apptocmd{\alltt}{\let~\alltthyphen}{}{}
\newcommand\alltthyphen{\@ifnextchar~{\@alltthyphen@i}{\char`\- }}
\def\@alltthyphen@i#1{% #1 is -
\@ifnextchar~{{\fontfamily{cmvtt}\selectfont---}\@gobble}{\char`\-\char`\- }%
}}
\makeatother
\begin{document}
\begin{alltt}
Please---will you give me an em dash?
PleaseXXwill you give me an em dash?
\end{alltt}
\end{document}
La salida es la misma que antes.
Solución demasiado complicada: falsificar un em-dash, porque la familia de fuentes no tiene una fuente de máquina de escribir de ancho variable
\documentclass{article}
\usepackage{alltt,etoolbox}
\usepackage{tgcursor}
\makeatletter
\begingroup\lccode`~=`-
\lowercase{\endgroup\apptocmd{\alltt}{\let~\alltthyphen}{}{}
\newcommand\alltthyphen{\@ifnextchar~{\@alltthyphen@i}{\char`\- }}
\def\@alltthyphen@i#1{% #1 is -
\@ifnextchar~{\fake@em@dash\@gobble}{\char`\-\char`\- }%
}}
\def\fake@em@dash{%
\sbox0{--}%
\makebox[\wd0][s]{-\hss-\hss-}%
}
\makeatother
\begin{document}
\begin{alltt}
Please---will you give me an em dash?
PleaseXXwill you give me an em dash?
\end{alltt}
\end{document}
Es posible que desees simplificar la configuración usando just --
en lugar de ---
; esto necesitaría cambios en las macros anteriores.