I’m writing a document in Italian that also contains English words. I want to italicize all the English words, but I don’t want to find all their occurrences throughout the document. I hope it’s possible to create something (maybe a command?) with which I specify a set of words so that they are italicized when compiling the document. Maybe it’s even possible to make sure all English words are automatically italicized. So far, I haven’t found anything that could answer my question, except for this, but the problem is that it regards just a particular word, while I need to specify a set of words.
Asked
Active
Viewed 637 times
2
2 Answers
1
A simple modification of this answer:
\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}
Fran
- 80,769
1
Here's a LuaLaTeX-based solution. It shows how to set up a comma-separated list of words as a Lua table, and it sets up a Lua function that sweeps over the input and renders any words that match one of the words in the table in italics.
Note that this code is anything but robust. E.g., if your document contains a macro called \foxhound or an environment called foxbat, very bad things are bound to happen.
I think you'd be better off encasing all instances of English-language words in your document manually in \textit statements.
% !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}
Mico
- 506,678

pdflatexorxelatex. I would anyway advise against it, having a macro like\newcommand{\EN}[1]{{\selectlanguage{english}\emph{#1}}}is easy and will guarantee a good result (you know what the word is, for LaTeX it is just a string of chars). – Rmano Sep 05 '20 at 10:21Questo è un \en{example}.is best, since it can make it italic and change hyphenations at the same time. – pst Sep 05 '20 at 12:12