A question very similar to mine was asked before, but I assume that there are others with the same issue and that there are other solutions. I know several academic publishers that don't like excessive use of capital letters in running text as it distracts heavily from reading. Instead, they use small caps for all-caps abbreviations and highlighted words.
As I am writing a tex-template for future use, I need a solution that affects all all-caps words without having to alter the .tex
-file. Moreover, this others having the same problem can take over the same solution without easily.
Goal: convert all all-caps words in a document into all small-caps.
Issues:
- We need to determine all-caps words and their boundaries before we can convert them.
- In most cases, the complete word needs to be in small-caps, including the first letter (as if
\textsc{\MakeLowercase{#1}}
), though some prefer the first letter to be a capital (as in answer to the question asked before). - A plural form of the abbreviations (e.g., URLs, CDs) contains an suffixed s, which should remain lowercase (as it always is).
Solutions: I have looked for various ways to solve this, but none gave me the correct solution yet.
using Lua code (in LuaLaTeX; cf. Lua Frontier Pattern and Macro: Replace all occurrences of a word). However, the following code does not work, possibly because it also affects LaTeX commands (I have been thinking to ignore/escape
\
, just as I would need to do with word-final -s).\usepackage{luacode} \begin{luacode} function capstosc ( s ) return unicode.utf8.gsub( s, "(%f[%a]%u+%f[%A])" , "{\\scshape\\MakeLowercase{#1}}") end \end{luacode} \AtBeginDocument{% \directlua{luatexbase.add_to_callback ( "process_input_buffer", capstosc, "capstosc" )}
l3regex
(with a similar RegEx search entry as above) but I have not found any way to apply this to the whole document text;a custom-made TeX-code; the other question has an answer that provides this, but it cannot be applied to the entire document and it does not seem to be able to be adjusted to ignore plural s's.
process_input_buffer
is not a good callback to use; probablypre_linebreak_filter
or something else will work better (and address the problem @UlrichDiez mentioned above). Of course then it's not a simple string substitution and you'd have to do more work.