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.

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
Jopie
  • 594
  • 1
    How to handle the case of an all-caps word being the result of expanding a macro which is defined in an external package? – Ulrich Diez Jan 02 '19 at 11:27
  • 2
    This is a great idea. Maybe someone could write a package. – jessexknight Jan 02 '19 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. – ShreevatsaR Jan 03 '19 at 05: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? – ShreevatsaR Jan 06 '19 at 09: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 '19 at 15:10
  • @ShreevatsaR Unfortunately, I do not have all the testing files, so I cannot recall the errors; as far as I remember, the first command/package after the luacode returned an error, which was solved by removing the luacode. From that I concluded that it affected any following command. – Jopie Jan 17 '19 at 15:15
  • If you don't have the testing files and can't reproduce the errors, how would you test an answer if it were given? As it stands the question is unclear about what exactly the problem(s) is (are), and it would have to be made more precise (including saying what exactly the other approaches tried were and problems they had) before having a chance of being answered. More precisely, there should be a test file such that if some solution works for that specific test file then the question will be considered definitely answered, rather than remain open-ended. – ShreevatsaR Jan 18 '19 at 08:17

0 Answers0