
Estou tentando digitar um travessão usando ---
dentro de um alltt
ambiente, mas recebo três hífens em vez de um único travessão.
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}
Resposta aos comentários Os comentários perguntaram por que desejo digitar um travessão em um ambiente monoespaçado. Eu gostaria de compor um travessão que se parecesse com um travessão, mas ocupasse o comprimento de dois espaços em um ambiente monoespaçado, ou seja, como "--", mas unidos para formar um único caractere semelhante a um travessão.
Responder1
Minha sugestão seria "ocultá-lo" na forma de uma macro de onde foi retirado o travessão \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 a fonte monoespaçada venha com um travessão, ela será definida como travessões separados. Você poderia forçar um travessão de aparência monoespaçada, talvez com uma definição \emdash
semelhante 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}
Algumas informações sobre líderes podem ser encontradas emQuer preencher a linha com uma string repetida.
Responder2
Solução simples: 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}
Observe que a primeira linha contém — (Unicode U+2014 EM DASH)
Solução mais complicada: transformar ---
em{\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}
A saída é a mesma de antes
Solução muito complicada: falsifique um travessão, porque a família de fontes não tem uma fonte de máquina de escrever de largura variável
\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}
Você pode simplificar a configuração usando just --
em vez de ---
; isso precisaria de alterações nas macros acima.