1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LaTeX→Qiita用MathJax変換マクロ@EmEditor

Last updated at Posted at 2020-05-01

__EmEditor__のマクロ機能を使って簡単な$\mathrm{\LaTeX}$文書をQiita用に変換する.
ついでに式番号も自動で振る.

変換対象
\section{定義}
\subsection{性質1}
\subsubsection{性質2}

\begin{align}
y=a,\label{eq:1}
\end{align}
ああああ
\begin{align}
y=b,
\end{align}
いいいい
\begin{align}
y=c,\label{eq:2}
\end{align}
ここで\ref{eq:1}\ref{eq:2}より…

\section{定義}
\begin{align}
f=a,
\end{align}

LaTeX2Qiita.jsee@EmEditor


# 定義
## 性質1
### 性質2


```math
\begin{align}
y=a,\tag{1}\label{eq:1}
\end{align}
```

ああああ

```math
\begin{align}
y=b,
\end{align}
```

いいいい

```math
\begin{align}
y=c,\tag{2}\label{eq:2}
\end{align}
```

ここで__($\ref{eq:1}$)__と__($\ref{eq:2}$)__より…

# 定義

```math
\begin{align}
f=a,
\end{align}
```

上記をそのままQiita記事として貼り付けると以下のように表示される:

定義

性質1

性質2

\begin{align}
y=a,\tag{1}\label{eq:1}
\end{align}

ああああ

\begin{align}
y=b,
\end{align}

いいいい

\begin{align}
y=c,\tag{2}\label{eq:2}
\end{align}

ここで__($\ref{eq:1}$)($\ref{eq:2}$)__より…

定義

\begin{align}
f=a,
\end{align}

ちなみに$\mathrm{\LaTeX}$では以下の図のように出力される:

image.png

ソース
\documentclass{jsarticle}
\usepackage{amsmath}
\begin{document}

\section{定義}
\subsection{性質1}
\subsubsection{性質2}

\begin{align}
y=a,\label{eq:1}
\end{align}
ああああ
\begin{align}
y=b,
\end{align}
いいいい
\begin{align}
y=c,\label{eq:2}
\end{align}
ここで\ref{eq:1}\ref{eq:2}より…

\section{定義}
\begin{align}
f=a,
\end{align}

\end{document}

マクロ本体

数式はいつも\align環境で書いてるのでそれにだけ対応.
テキスト形式で保存してマクロメニューから追加するだけ.

LaTeX2Qiita.jsee
document.selection.Replace( "\%.*", '', eeFindReplaceRegExp|eeReplaceAll );
document.selection.Replace( "\\begin{align}", "\n```math\n\\begin{align}", eeReplaceAll );
document.selection.Replace( "\\end{align}", "\\end{align}\n```\n",eeReplaceAll );
document.selection.Replace( '\\\\Ref\{(.*?)\}', '__\(\$\\\\ref\{$1\}\$\)__', eeFindReplaceRegExp|eeReplaceAll);
document.selection.Replace( "\\label", "\\tag{}\\label", eeReplaceAll );
document.selection.Replace( "(<|>)", '\ $1\ ', eeFindReplaceRegExp|eeReplaceAll );
document.selection.Replace( "\\\\section\{(.*?)\}", '# $1', eeFindReplaceRegExp|eeReplaceAll );
document.selection.Replace( "\\\\subsection\{(.*?)\}", '## $1', eeFindReplaceRegExp|eeReplaceAll );
document.selection.Replace( "\\\\subsubsection\{(.*?)\}", '### $1', eeFindReplaceRegExp|eeReplaceAll );
document.selection.StartOfDocument();
for (var i=1; document.selection.Replace( "\\tag{}", "\\tag{"+i+"}", eeFindNext )>0;++i){}

トラブルシューティング

 うまくいってるはずなのに表示がおかしいときは,F5更新したり,下付き添字のアンダーバーをエスケープしてみたりする.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?