
Я пишу документ на итальянском языке, который также содержит английские слова. Я хочу выделить курсивом все английские слова, но не хочу находить все их вхождения в документе. Надеюсь, можно создать что-то (может быть, команду?), с помощью которой я укажу набор слов, чтобы они выделялись курсивом при компиляции документа. Может быть, даже можно сделать так, чтобы все английские слова автоматически выделялись курсивом. Пока что я не нашел ничего, что могло бы ответить на мой вопрос, кромеэтот, но проблема в том, что это касается только конкретного слова, тогда как мне нужно указать набор слов.
решение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}