
我正在嘗試用連字號連接長關鍵字,如範例所示:
\documentclass[10pt]{article}
\usepackage{underscore}
\begin{document}
\pagestyle{empty}
\parbox{1pt}{TESTSTRING\_TESTSTRING\_HYPHENATION}
\\\\
%\begin{figure}[here]
%\centerline{\includegraphics*[width=0.8\paperwidth]{/pictures/regular_testname.png}}
%\centerline{\includegraphics*[width=0.8\paperwidth]{/pictures/escaped\_testname.png}}
%\end{figure}
\end{document}
我試過這和這還有更多沒有成功。如果我取消註解範例中的數字,則underscore
-package 會產生問題,因為檔案名稱中的底線不再被正確解釋。如果不使用這個包,可以插入圖片,但我的字串沒有連字號。
您是否知道如何在本地正確地連字符,例如:TESTSTRING\myUnderTESTSTRING\myUnderHYPHENATION
?
如何控制連字號連接字串時不寫入連字號?這會更好。
作為一個附帶問題:在我的範例中,為什麼字串的第一部分沒有用連字號連接?
答案1
也許這樣的東西會有所幫助,而不使用underscore
您似乎更喜歡的包(不使用它)。它啟動連字符 with並恢復with\newuson
的原始定義。透過這種開/關機制,您可以控制修改的範圍。\_
\newusoff
另外,底線的「連字號」沒有破折號,如果我正確理解了這個問題,這似乎也是所期望的。
無論如何,要使段落的第一個單字連字符,\hspace{0pt}
需要以 a 開頭該段落。
\documentclass{article}
%\usepackage{underscore}
\textwidth0pt
\let\svus\_
\newcommand\newuson{\def\_{\svus\allowbreak\hspace{0pt}}}
\newcommand\newusoff{\let\_\svus}
\begin{document}
TESTSTRING\_TESTSTRING\_HYPHENATION
\newuson
\hspace{0pt}TESTSTRING\_TESTSTRING\_HYPHENATION
\newusoff
TESTSTRING\_TESTSTRING\_HYPHENATION
\end{document}
答案2
如果您熱衷於將帶下劃線的長字串保留為巨集的參數,這很簡單:
\documentclass[10pt]{article}
\DeclareRobustCommand\Name[1]{{%
\let\_\hyphenationunderscore#1%
}}
\newcommand{\hyphenationunderscore}{%
\textunderscore\nobreak\hspace{0pt}%
}
\begin{document}
\pagestyle{empty}
\parbox{1pt}{
\hspace{0pt}%
\Name{TESTSTRING\_TESTSTRING\_HYPHENATION}
}
\end{document}
您也可以\_
全域重新定義:
\documentclass[10pt]{article}
\renewcommand{\_}{%
\textunderscore\nobreak\hspace{0pt}%
}
\begin{document}
\pagestyle{empty}
\parbox{1pt}{
\hspace{0pt}%
TESTSTRING\_TESTSTRING\_HYPHENATION
}
\end{document}
或者,您可以_
啟動:
\documentclass[10pt]{article}
\newcommand{\hyphenationunderscore}{%
\textunderscore\nobreak\hspace{0pt}%
}
\catcode`_=\active
\protected\def_{\ifmmode\sb\else\hyphenationunderscore\fi}
\begin{document}
\pagestyle{empty}
\parbox{1pt}{
\hspace{0pt}%
TESTSTRING_TESTSTRING_HYPHENATION
}
\end{document}
請注意,如果沒有,\hspace{0pt}
中就不會出現連字符\parbox
,因為 TeX 不會對前面沒有粘連的單詞進行連字符。
如果您想在下劃線之後也中斷,請更改\nobreak
為\linebreak[0]
全文。例如,第二個解決方案變為
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\renewcommand{\_}{%
\textunderscore\linebreak[0]\hspace{0pt}%
}
\begin{document}
\pagestyle{empty}
TESTSTRING\_TESTSTRING\_HYPHENATION
\parbox{1pt}{
\hspace{0pt}%
TESTSTRING\_TESTSTRING\_HYPHENATION
}
\end{document}
這裡的輸出也顯示了 T1 發生的情況。