Text Formattingenvironment specific \renewcommand?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Matifou
Posts: 23
Joined: Fri Jan 14, 2011 11:27 am

environment specific \renewcommand?

Post by Matifou »

Hi

I wrote my all text with % and now editor says it should be percent... Is there a way to simply change the command \% to mean percent, but not in math evironment?

I can easily do

Code: Select all

\renewcommand{\%}{ percent}
but then \% in math will be written percent... can I define it to change only in non-math environment?

Thanks!!
Last edited by Matifou on Fri Jan 28, 2011 5:07 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

environment specific \renewcommand?

Post by frabjous »

You could redefine the command to contain a conditional defined in terms of the TeX primitive ifmmode (if math mode...) check:

Code: Select all

\let\oldpercent=\%
\renewcommand{\%}{\ifmmode\oldpercent\else\ percent\fi}
Matifou
Posts: 23
Joined: Fri Jan 14, 2011 11:27 am

Re: environment specific \renewcommand?

Post by Matifou »

great, thanks a lot!!!!
Post Reply