
私はイタリア語で英語の単語も含む文書を書いています。英語の単語をすべて斜体にしたいのですが、文書全体でそれらの出現箇所をすべて検索したいわけではありません。文書をコンパイルするときに斜体になるように単語のセットを指定する何か(おそらくコマンド?)を作成できればと思います。すべての英語の単語が自動的に斜体になるようにすることもおそらく可能です。これまでのところ、私の質問に答えてくれるものは何も見つかりませんでした。これしかし、問題は、単語のセットを指定する必要があるのに、特定の単語だけを対象としていることです。
答え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}