LyX ⇒ how to switch the language between text and math?
how to switch the language between text and math?
I need to know if there is a posibility for automaticaly change the language between text and math mode. I use romanian in text, but I need english when I insert math formula because of the keyboard layout diferences.
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
how to switch the language between text and math?
There are two hooks which can be used:
Stefan
\everymath
is called every time when it's switched to inline math,\everydisplay
is called every time when it's switched to displayed math, for example in equation environments.
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage[ngerman,english]{babel}% loading two languages\everymath{\selectlanguage{ngerman}}\everydisplay{\selectlanguage{ngerman}}\usepackage{amsmath}\usepackage{parskip}\begin{document}tes"-ting english% ngerman shortcut "- doesn't work, but is visible instead% i.e. ngerman is not active, but english$\text{tes"-ting ngerman}$% here, "- works and is hidden, ngerman is activetes"-ting english% again, ngerman shortcut "- doesn't work, english is active\[ \text{tes"-ting ngerman} \]% also here, "- works and is hidden, ngerman is activetes"-ting english% ngerman shortcut "- doesn't work any more, english is active again\end{document}
LaTeX.org admin
Re: how to switch the language between text and math?
Thank you for your effort, but I don't know how to implement your solution to make it work in my documents.
how to switch the language between text and math?
You need to add
(or which language you want to have inside math) to the document preamble under Document>Settings>LaTeX Preamble.
Make sure you also choose language=none in the language settings.
Regards
Code: Select all
Code, edit and compile here:
\usepackage[ngerman,english]{babel}% last language in list will be document language\everymath{\selectlanguage{ngerman}}\everydisplay{\selectlanguage{ngerman}}
Make sure you also choose language=none in the language settings.
Regards
site moderator & package author
Re: how to switch the language between text and math?
I did this, but I can't see any difference. It doesn't automaticaly change my keyboard layout.
Thanks.
Thanks.
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Re: how to switch the language between text and math?
The code above changes the language support, such as hyphenation. However, the keyboard layout depends on your operating system and this cannot be changed by LaTeX, except making external calls to a software which changes the keyboard layout. You would need such a software first.
Stefan
Stefan
LaTeX.org admin
Re: how to switch the language between text and math?
Now I understand. Thanks for your help.