TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Lyx with Preamble. I am working on a project where the abbreviation "hon." needs to be set to small caps globally. (/sc). Tried to use \renewcommand, no luck there.


share|improve this question
You might need to elaborate a bit on that. Tried to use \renewcommand on what exactly? Might be a good idea to provide a MWE. – daleif Sep 14 '12 at 15:49
I suspect that he tried to write \renewcommand{hon.}{{\sc hon.}} or something similar. – Niel de Beaudrap Sep 14 '12 at 15:59
Cheers Kurts for pointing it out. @daleif I was trying what Beaudrap said, but with little success. – Shi Yuan Sep 14 '12 at 16:26

I think I see what you want. In LyX, type the text "LyX" and export to pdf. You will see that it is formatted automatically. Is that what you want?

There is no user-friendly way to add your own special phrase as these (also "TeX", "LaTeX2e", "LaTeX") are hardcoded. However, if you can compile LyX, it's very easy to add your own:

(1) Edit src/Paragraph.cpp and edit the special_phrase array as follows:

special_phrase const special_phrases[] = {
        { "LyX", from_ascii("\\LyX{}"), false },
        { "TeX", from_ascii("\\TeX{}"), true },
        { "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
        { "LaTeX", from_ascii("\\LaTeX{}"), true },
        { "hon.", from_ascii("\\hon{}"), false },

(1.5, optional) Note that you should also change src/tex2lyx/text.cpp so that if you import a tex file with "hon." LyX does not try to change it. This is easy -- just add "hon." to the known_phrases and known_coded_phrases arrays.

(2) (re)compile.

(3) Then in your preamble put

\newcommand{\hon}{{\sc hon.}}

The reason it's a good idea to have a middleman, \hon{}, is so that you can easily change it in the preamble and you won't have to recompile.

That should do what you want. I'm not sure it's a good idea though. Note that if you input Mathew is planning to run a marathon., the hon. will still be substituted for. If you're quick enough to catch that would-be error, instead of marathon. put marathon[put an empty ERT box here]. and the output will be as intended.

An alternative way to the above would be to use a python script.

share|improve this answer

Probably the simplest approach is to use a macro specifically for "hon." wherever it appears.

Surely, if the \Hon\ Member found himself in that position \emph{etc.}

Note the backslash after the macro \Hon. Nearly (but not quite all) macros consume all whitespace after the occur, including any which are defined by \newcommand or \renewcommand under ordinary circumstances. The backslash immediately after the macro preserves the whitespace which occurs immediately afterwards.

share|improve this answer
Thanks Beaudrap, but is there a way to change the style to small caps without modifying the original text? – Shi Yuan Sep 14 '12 at 16:25
if I can put it into an analogy, I would like to achieve the same function as the GREP style in InDesign. – Shi Yuan Sep 14 '12 at 16:28
That's not easy in LaTeX, but you can use your prefered editor to search and replace hon. with \Hon in your files. – Juri Robl Sep 14 '12 at 21:13
Yes, and also note that LyX's advanced search and replace, Edit > Find & Replace (Advanced) might be useful here – scottkosty Sep 14 '12 at 21:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.