Skip to content

Instantly share code, notes, and snippets.

@hyuki
Last active April 25, 2018 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/2ef89af7d855e3b37cd741598fdb786f to your computer and use it in GitHub Desktop.
Save hyuki/2ef89af7d855e3b37cd741598fdb786f to your computer and use it in GitHub Desktop.
数式でディスプレイスタイルとそれ以外を自動判定するLaTeXマクロはどう書くの?(コメントで解決)
\documentclass{jsarticle}
\begin{document}
\newcommand{\TEST}{(\ifinner \texttt{i} \fi%
\ifmmode \texttt{m} \fi)}
\section*{1}
$\TEST$
\section*{2}
$$
\TEST
$$
\section*{3}
$\begin{array}{c}\TEST\end{array}$
\section*{4}
$$
\begin{array}{c}\TEST\end{array}
$$
\section*{5}
$$
\begin{array}{c}\displaystyle\TEST\end{array}
$$
\end{document}
@hyuki
Copy link
Author

hyuki commented Apr 25, 2018

20180425155122

できれば 4 で、せめて 5 で (im) ではなく (m) が表示されるようにしたい。

@hyuki
Copy link
Author

hyuki commented Apr 25, 2018

\documentclass{jsarticle}
\begin{document}

% See TeXbook, EXERCISE 17.15.
\def\TEST{\mathchoice%
{D}%
{T}%
{S}%
{SS}}%

\section*{1}

$\TEST$

\section*{2}

$$
\TEST
$$

\section*{3}

$\begin{array}{c}\TEST\end{array}$

\section*{4}

$$
\begin{array}{c}\TEST\end{array}
$$

\section*{5}

$$
\begin{array}{c}\displaystyle\TEST\end{array}
$$

\section*{6}

$\TEST^{\TEST^{\TEST}}$


\end{document}

20180425175038

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment