我可以指定一组单词在整个文档中以斜体显示吗?

我可以指定一组单词在整个文档中以斜体显示吗?

我正在用意大利语编写一份文档,其中也包含英语单词。我想将所有英语单词都用斜体显示,但我不想在整个文档中查找它们的所有出现。我希望可以创建一些东西(也许是命令?),用它指定一组单词,以便在编译文档时将它们用斜体显示。也许甚至可以确保所有英语单词都自动用斜体显示。到目前为止,我还没有找到任何可以回答我的问题的东西,除了但问题是它只涉及一个特定的词,而我需要指定一组词。

答案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}

相关内容