
В моей библиографии я хочу включить номера отчетов технических отчетов шрифтом телетайпа. Эти номера отчетов обычно состоят из нескольких блоков букв и цифр, соединенных дефисами, например INSTITUTE-YEAR-MM-NUMBER
. В номерах отчетов нормально иметь перенос строки после любого из дефисов.
До сих пор я использовал его \nolinkurl
без особых раздумий, и он дает хорошие результаты. Теперь мне нужно включить номера отчетов, в которых один блок отделен от остальных пробелом. Этот пробел подавляется \nolinkurl
.В этом вопросена тот же вопрос, принятый ответ — использовать \texttt
вместо этого. Однако с \texttt
автоматические переносы строк не работают.
Минимальный пример:
\documentclass[12pt]{article}
\PassOptionsToPackage{hyphens}{url}
\usepackage[breaklinks]{hyperref}
\usepackage{showframe}
\newcommand{\thereport}{REPORT-19-12-001 SPECIAL}
\begin{document}
This is a long line and at the end of the line there should be \texttt{\thereport} referenced.
This is a long line and at the end of the line there should be \nolinkurl{\thereport} referenced.
\end{document}
Как сделать так, чтобы номера отчетов содержали дефисы и пробелы шрифтом телетайпа с автоматическими переносами строк?
решение1
Используйте \path
, с модификацией для расширения содержимого.
\documentclass[12pt]{article}
\PassOptionsToPackage{hyphens,obeyspaces}{url}
\usepackage{hyperref}
\usepackage{showframe}
\newcommand{\epath}[1]{\expandafter\path\expandafter{#1}}
\newcommand{\thereport}{REPORT-19-12-001 SPECIAL}
\begin{document}
This is a long line and at the end of the line there should be
\epath{\thereport} referenced.
\end{document}
решение2
Вы можете использовать пакет hyphenat:
\documentclass[12pt]{article}
\PassOptionsToPackage{hyphens}{url}
\usepackage[breaklinks]{hyperref}
\usepackage{showframe}
\newcommand{\thereport}{REPORT-19-12-001 SPECIAL}
\usepackage[htt]{hyphenat}
\begin{document}
This is a long line and at the end of the line there should be \texttt{\thereport} referenced.
This is a long line and at the end of the line there should be \nolinkurl{\thereport} referenced.
\end{document}
Или вы можете сбросить символ дефиса \ttfamily \hyphenchar\font=45
(в преамбуле).