파워포인트에 tex equation 집어넣기

파워포인트 2007에 있는 equation editor의 불편함에 치를 떨다가, latex을 이용해 발표 자료를 만들었다.
덴장.. 이것은 이것 나름대로 불편하기에, 짜증내다가 결국 방법을 하나 만들었다.

인터넷 검색을 해 보니  tex2gif 라는 게 있더군.

그런데 써 보니 편하긴 한데, gif 포맷이라는게 좀 흠이다. 그래서 또다시 웹을 검색하다 보니 eps 포맷은 파워포인트에 또 깔끔하게 붙는다는군. 그래서 tex2gif.py 소스를 좀 고쳐서 tex2eps.py 를 만들었다. 유후~ 이렇게 깔끔할 수가...

그리고 문득 든 생각... tex2eps.py 의 UI가 너무 불편하다. 수식도 완전 일회용으로 사용해야 되고... 그래서 vim에서 불러 쓸 수 있는 코드를 만들었다. 일단 .vimrc 에 추가한 내용. 마지막에 map 을 이용해서 \eq 를 누르면 현재 편집하고 있는 라인에 대해 수식을 eps 파일로 만들어 준다.

==================================================================
function! TexEq_CurrentLine()
let l = getline('.')
let list = [l]
call writefile(list, '.texeq_temp.eq')
call system('texeq.py .texeq_temp.eq')
call delete('.texeq_temp.eq')
endfunction

au BufNewFile,BufReadPost *.tex map \eq :call TexEq_CurrentLine()<CR>
==================================================================

그리고 eps를 만들어 주는 python 스크립트
C:\WINDOWS 에 넣어놓고 사용중이다.

==================================================================
texeq.py
==================================================================
#!/usr/bin/python
#
# texeq
#
# Sunghyun Cho
# http://home.postech.ac.kr/~sodomau
# sodomau__at__postech.ac.kr

header = """\
\documentclass[12pt]{article}
\pagestyle{empty}
\\begin{document}
\\begin{displaymath}
"""

footer = """\
\end{displaymath}
\end{document}
"""

import string,os,sys

if len(sys.argv) == 1:
latexstring = raw_input()
else:
f = open(sys.argv[1], 'r')
latexstring = f.readline().strip()
f.close()

# make a latex file
f = open('.texeq_temp.tex','w')
f.write('%s' % header)
f.write('%s\n' % latexstring)
f.write('%s\n' % footer)
f.close()

# make an eps file
os.system('latex .texeq_temp.tex')
os.system('dvips -f .texeq_temp.dvi > .texeq_temp.ps')
os.system('ps2eps.bat -f .texeq_temp.ps')

# enlarge the bounding box of the eps file a little bit
f = open('.texeq_temp.eps', 'r')
lines = f.readlines()
f.close()

tokens = lines[1].strip().split(' ')
l = int(tokens[1])
d = int(tokens[2])
r = int(tokens[3])
u = int(tokens[4])
lines[1] = "%s %d %d %d %d\n" % (tokens[0], l-1, d-1, r+1, u+1)

tokens = lines[1].strip().split(' ')
l = float(tokens[1])
d = float(tokens[2])
r = float(tokens[3])
u = float(tokens[4])
lines[2] = "%s %f %f %f %f\n" % (tokens[0], l-1.0, d-1.0, r+1.0, u+1.0)

f = open('equation.eps', 'w')
f.writelines(lines)
f.close()

# cleanup
os.unlink('.texeq_temp.tex')
os.unlink('.texeq_temp.aux')
os.unlink('.texeq_temp.log')
os.unlink('.texeq_temp.ps')
os.unlink('.texeq_temp.dvi')
os.unlink('.texeq_temp.eps')

==================================================================


by ㅅㅎ | 2009/09/19 05:00 | 트랙백(1) | 덧글(1)

시그랩 아시아 2009 논문 됐다!

그동안 고생 많았다. 후후

앞으로도 잘 하자!

by ㅅㅎ | 2009/09/04 04:23 | 매일매일 | 트랙백 | 덧글(6)

◀ 이전 페이지          다음 페이지 ▶