LoginSignup
0
3

More than 5 years have passed since last update.

LaTeXからワードファイルを出力する

Posted at

はじめに

  • 文章作成:tex形式
    • 論文入稿時の要請
    • 個人的な好み
  • 共著者とのやりとり: docx形式
    • コメント・変更履歴が残しやすい

tex形式からdocx形式への変換を楽にするには?...という覚書

基本方針

  • pandocやAdobe Acrobatを使えば良い
    • ただし,数式や画像(pdfやeps)が乱れる事しばしば
    • 行・ページ番号があると,さらにグダグダに

そこで,基本的には既存のサービスを使いつつも

  • 数式や画像は後から(画像として)貼り付け
  • 共著者チェック時は,行・ページ番号を未記載 (あるいは,ワードの機能で再表示)

という抜け穴を使って,変換してみる

実装

プリアンブル

\newif\ifoutpdf
\outpdftrue  % pdf形式で出力
\outpdffalse % docx形式で出力
\ifoutpdf
  % 行番号の適切な表示*****始まり
  % このブロックがないと,数式前後で行番号が乱れる
  \newcommand*\patchAmsMathEnvironmentForLineno[1]{%
  \expandafter\let\csname old#1\expandafter\endcsname\csname #1\endcsname
  \expandafter\let\csname oldend#1\expandafter\endcsname\csname end#1\endcsname
  \renewenvironment{#1}%
     {\linenomath\csname old#1\endcsname}%
     {\csname oldend#1\endcsname\endlinenomath}}% 
  \newcommand*\patchBothAmsMathEnvironmentsForLineno[1]{%
  \patchAmsMathEnvironmentForLineno{#1}%
  \patchAmsMathEnvironmentForLineno{#1*}}%
  \AtBeginDocument{%
  \patchBothAmsMathEnvironmentsForLineno{equation}%
  \patchBothAmsMathEnvironmentsForLineno{align}%
  \patchBothAmsMathEnvironmentsForLineno{flalign}%
  \patchBothAmsMathEnvironmentsForLineno{alignat}%
  \patchBothAmsMathEnvironmentsForLineno{gather}%
  \patchBothAmsMathEnvironmentsForLineno{multline}%
  % 行番号の適切な表示*****終わり
}
\else
  % ハイフネーションの禁止
  \hyphenpenalty=10000\relax
  \exhyphenpenalty=10000\relax
  \sloppy
  % ページ番号未表示
  \pagestyle{empty}
\fi

本文

数式

数式が1行の場合
\begin{align}
  \ifoutpdf
    % 数式本文
    \label{eq:**}
  \fi
\end{align} 
数式が複数行の場合
\ifoutpdf
  \begin{align}
    % 数式本文
    \label{eq:**}
  \end{align}
\else
  \begin{align}
    temp
    \label{eq:**}
  \end{align}
\fi

図表

\begin{figure}[p]
  \centering
  \ifoutpdf
    \includegraphics{**} 
  \fi
  \caption{
    % キャプション
  }
  \label{fig:**}
\end{figure}

docx形式への出力手順

  1. \outpdffalseを指定
    • ページ・行番号は出力されない
    • 図表・数式は出力されない
    • 図表・数式番号,及びキャプションは出力される
  2. docx形式へ出力
    • dvipdfxで処理 (pdf形式で出力)→Adobe Acrobatを用い,docxとして出力
    • あるいは,pandocで処理
  3. 図表・数式の差込
    • 数式に関しては,Word機能を使って再入力しても良い
    • が,面倒なのでpdfで出力したものをキャプチャーし,画像として貼り付ければ用は足りる

問題点

  • 数式の再入力 (あるいはキャプチャーからの画像貼付)が,やはり面倒
    • なんとかしてここも自動化できないか...
0
3
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
0
3