파워포인트에 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)

트랙백 주소 : http://sodomau.egloos.com/tb/2429722
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Tracked from Pensées at 2009/09/24 04:02

제목 : 파워포인트에 tex 수식 집어넣기 2
이전글 : 파워포인트에 tex equation 집어넣기 업데이트 버전 이번에는 cygwin용 bash 스크립트다.eps가 파워포인트에서 렌더링이 하도 구리게 되서 다시 이미지 파일로 쓰기로 변경했다.최종은 equation.png 파일로 저장되는데, 이미지 크기와 함께 dpi를 높게 설정해서 파워포인트에 붙일 때 적절한 크기로 붙으면서 어느 크기에서든 잘 보이게 업데이트했다. .vimrc=========================......more

Commented by 크로 at 2009/09/19 14:22
이거 파이썬 스크립트 말고 그냥 실행 파일로는 못만드나? 그리고 .pdf로도 출력하면 파워포인트에 잘 붙을 거 같은데 pdf는 문제가 있던가...

:         :

:

비공개 덧글

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