3

See this minimal example

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{marathi}
\usepackage[no-math]{fontspec}
\setmainfont[Script=Devanagari,Mapping=devanagarinumerals]{Shobhika}

\begin{document}
    \ensuremath{\frac{१}{२}}
\end{document}

I need no-math option for a purpose which is not necessary in this MWE, but I also want to type \frac command once. How to turn off no-math option (which was initially declared globally) for a short scope in the document.

3
  • 1
    Unrelated to the question, but this usage of \ensuremath is wrong. Jan 7, 2020 at 1:18
  • Actually I want to use this in a glossary entry. I was getting an error with $$, hence I used ensuremath. What is the correct use of it?
    – Niranjan
    Jan 7, 2020 at 8:47
  • If it gives you errors with $...$ then removed the $. See also tex.stackexchange.com/a/35877 Jan 7, 2020 at 9:08

2 Answers 2

5

Use \text:

\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{marathi}
\setmainfont[Script=Devanagari,Mapping=devanagarinumerals]{Shobhika}
\usepackage{amsmath}

\begin{document}

$\frac{\text{१}}{\text{२}}$

\end{document}

enter image description here

1
  • 1
    Great. This worked perfectly. Thanks!
    – Niranjan
    Jan 6, 2020 at 17:01
1

You ask how to temporarily turn off a global option.

In general you have to look at the code (in the class or package) that sets the global option, create a macro that negates that code and also a macro that reinstates the option code. Something along the lines:

\documentclass[opta]{...}
\newcommand{\killopta}{...}
\newcommand{\enableopta}{...}
%
\begin{document}
bla bla bla
\killopta % disable option opta
more blas
\enableopta % reenable option opta
yet more blas
\end{document}

ADDITION

In a comment the OP asked how to deal the the nomath option in the fontspec package.

I have never used fontspec but looking at the fonspec code as given in fontspec-luatex.sty there is the following code:

\DeclareOption {math}    {\bool_gset_true:N \g__fontspec_math_bool }
\DeclareOption {no-math} { \bool_gset_false:N \g__fontspec_math_bool }

I would guess that creating two new commands, say \mathon and \mathoff whose definitions are the same as for the math and no-math options would enable you to switch between them in the document.

2
  • So for example I want to use nomath option provided by package fontspec. How to do it with your trick?
    – Niranjan
    Jan 9, 2020 at 1:36
  • @Niranjan I have extended my answer to try and deal with your extended question. If it does not work then ask a specific question about your problem Jan 9, 2020 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .