LoginSignup
0
0

More than 3 years have passed since last update.

orgファイルをpdfにする方法

Last updated at Posted at 2020-06-04

手順

1.まず以下の様なRakefileを、変換したいorgファイルのある所へコピーする。

-written by Yamamoto Kenta

file = Dir.glob("*.org")[0].match(/(.*).org/)[1]

desc "platex"
task :platex do
  lines = File.readlines("#{file}.tex")
  t_file = "thesis_midterm"
  lines = convert_thesis(lines)
  File.open("#{t_file}.tex", "w") do |f|
    lines.each { |line| f.print line }
  end
  #system "platex #{file}"
  commands = ["platex #{t_file}.tex",
              "bibtex #{t_file}.tex",
              "platex #{t_file}.tex",
              "dvipdfmx #{t_file}.dvi",
              "open #{t_file}.pdf"]
  commands.each { |com| system com }
end

def convert_thesis(lines)
  head = <<'EOS'
  \documentclass[a4j,twocolumn]{jsarticle}
  \usepackage[dvipdfmx]{graphicx}
  \usepackage{url}

  \setlength{\textheight}{275mm}
  \headheight 5mm
  \topmargin -30mm
  \textwidth 185mm
  \oddsidemargin -15mm
  \evensidemargin -15mm
  \pagestyle{empty}


  \begin{document} 

  \title{核崩壊と核分裂の違いについて}
  \author{情報科学科 \hspace{5mm} 27017561 \hspace{5mm} 山本 健太}
  \date{}

  \maketitle
EOS
  head2 = <<'EOS'
  {\small\setlength\baselineskip{15pt}  % 参考文献は小さめの文字で行間を詰めてある
  \begin{thebibliography}{9}
  \bibitem{houkai} 「放射性崩壊 wikipedia」,(https://ja.wikipedia.org/wiki/放射性崩壊).
  \bibitem{bunretu} 「核分裂反応 wikipedia」,(https://ja.wikipedia.org/wiki/核分裂反応).
  \bibitem{gakusei} 「原子核崩壊のメカニズムとは?理系学生のライターが詳しく解説!」,(https://study-z.net/100061260).
  \end{thebibliography}
  }
  \end{document}
EOS
  new_line = [head]
  lines[32..-1].each do |line|
    #    if line.match(/\\tableofcontents\n/)
    #      line = "\\tableofcontents\n\\listoftables\n\\listoffigures\n\\pagebreak\n"
    #      p line
    #    end
    new_line << line
  end

  new_line.each do |line|
    line.gsub!('\end{document}', head2)
    # line.gsub!('\tableofcontents','\begin{document}')
    line.gsub!('\tableofcontents', "")
  end
  return new_line
end

desc "test"
task :test do
  #str = Dir.glob("*.org")[0].match(/(.*).org/)[1]
  str = Dir.glob("*.org")
  p str
end

2.emacsでorgファイルを開き、そこで”C-c C-e ll”のコマンドを実行しemacsを閉じる。

3.orgファイルと同じ名前のテキストが表示されているはずなので、terminalで”rake platex”を実行する。

4.pdf化される。

注 2番でうまくいかなかった場合

私も手順2でうまくいかなかった。
terminalで”which ruby”と打つと、/usr/bin/emacs と出てきたため、pathがうまく通っていない事が原因である事がわかった。
pathを通そうとしたが、うまくできなかったので応急処置として、/usr/local/bin/emacs 〇〇.org といった様に直接pathを通す事で解決した。

今後、pathの通し方がわかればここにメモしようと思う。

takagi

0
0
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
0