7

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.

7
  • How to handle the case of an all-caps word being the result of expanding a macro which is defined in an external package? Jan 2, 2019 at 11:27
  • 2
    This is a great idea. Maybe someone could write a package. Jan 2, 2019 at 15:58
  • Yeah process_input_buffer is not a good callback to use; probably pre_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. Jan 3, 2019 at 5:16
  • Can you clarify what you mean by “However, the following code does not work, possibly because it also affects LaTeX commands”? What does “does not work” mean here, and do you have LaTeX commands with caps in them that were being modified, and which you want to ignore? Jan 6, 2019 at 9:38
  • @UlrichDiez ideally that would be affected as well. The typographic style simply forbids all-caps words. But I understand that is an extra difficulty.
    – Jopie
    Jan 17, 2019 at 15:10

0

You must log in to answer this question.

Browse other questions tagged .