
我正在用意大利語編寫一份文檔,其中也包含英語單字。我想將所有英文單字斜體化,但我不想在整個文件中找到它們出現的所有情況。我希望可以創建一些東西(也許是命令?),用它來指定一組單詞,以便在編譯文件時將它們顯示為斜體。也許甚至可以確保所有英語單字自動變為斜體。到目前為止,我還沒有找到任何可以回答我的問題的東西,除了這,但問題是它只考慮一個特定的單詞,而我需要指定一組單字。
答案1
一個簡單的修改這個答案:
\documentclass{article}
\usepackage{xesearch}
\UndoBoundary{-} % allow hyphens!!
\SearchList{italics}{\emph{#1}}{antibod?,covid?,infection,rna,DNA,*ELISA,*WHO,?pcr,%
RT-pcr,Multiplex-PCR,usa,UK,SARS?,virus,sensit?,test?}
\begin{document}
Mr. So and So, from the
WHO, % organization,
who % common word, must be not changed
has announced yesterday in the UK and the USA that the
ELISA % method acronym, must be changed
test to detect antibodies against SARS-CoV-2
in COVID-19 patients with first signs of the disease is useless,
said now that even PCR methods,
like RT-PCR
nested PCR,
quantitative PCR,
and Multiplex-PCR test,
used too early in the course of infection
are not enough sensitives.
On the other hand, the researcher
Elisa % Woman name, must be not changed
Whoknow proposed a WHO meetings to discuss the
disgnostic protocols of SARS and RNA virus and the sensitivity of a new indirect antibody test.
\StopList{italics}
\end{document}
答案2
這是一個基於 LuaLaTeX 的解決方案。它展示瞭如何將逗號分隔的單字清單設為 Lua 表,並設定 Lua 函數來掃描輸入並以斜體顯示與表中單字之一相符的任何單字。
請注意,這段程式碼一點也不健壯。例如,如果您的文件包含一個名為 的巨集\foxhound
或一個名為 的環境foxbat
,則必然會發生非常糟糕的事情。
我認為您最好將文件中所有英文單字的實例手動包含在\textit
語句中。
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry}
\usepackage[english,italian]{babel}
\usepackage{luacode}
%% Lua-side code: (a) Lua table with English words,
%% (b) Lua function that renders words in the table in italics
\begin{luacode}
en_words_list = {"The","quick","brown","fox","jumps","over","the","lazy","dog"}
function italicize_english_words ( s )
for i=1,#en_words_list do
s = s:gsub ( en_words_list[i] , "\\textit{%0}" )
end
return s
end
\end{luacode}
%% LaTeX-side code: Macros to activate/deactivate the Lua function:
\newcommand\EnWordsOn{\directlua{
luatexbase.add_to_callback(
"process_input_buffer" , italicize_english_words , "enwords" )}}
\newcommand\EnWordsOff{\directlua{
luatexbase.remove_from_callback(
"process_input_buffer" , "enwords" )}}
\begin{document}
\EnWordsOn % Activate the Lua function
la rapida volpe marrone---the quick brown fox---salta sopra---jumps over---il cane pigro---the lazy dog
\end{document}