$$y = x^2 + \frac{2}{3}\cdot x - 1$$이므로 다음 식이 성립한다. \[\displaystyle{\int\frac{e^{3x}}{1+e^{3x}}\,dx}=\displaystyle\frac13\ln(1+e^{3x})+\mathcal C.\] ok?
$ENV{PATH} = "/bin:/usr/bin/"; # 기존의 값 뒤에 콜론(:)을 써서 각 프로그램들이 있는 경로를 붙여적는다. ### LaTeX 변환 지원 $UseLatex = 1; # 1 = Use LaTeX conversion 2 = Don't convert
### 패치를 위해 추가된 환경설정 변수 use vars qw( ... $UseLatex # 추가 ); ###
sub CommonMarkup { ... s/\&__LT__;code\&__GT__;((.|\n)*?)\&__LT__;\/code\&__GT__;/&StorePre($1, "code")/ige; ############### ### added by gypark ### LaTeX 지원 - 이 단락 추가 if ($UseLatex) { # s/\$\$((.|\n)*?)\$\$/&StoreRaw(&MakeLaTeX("\$"."$1"."\$", "display"))/ige; # s/\$((.|\n)*?)\$/&StoreRaw(&MakeLaTeX("\$"."$1"."\$", "inline"))/ige; s/\\\[((.|\n)*?)\\\]/&StoreRaw(&MakeLaTeX("\$"."$1"."\$", "display"))/ige; s/\$\$((.|\n)*?)\$\$/&StoreRaw(&MakeLaTeX("\$"."$1"."\$", "inline"))/ige; } ### ############### ... }
다음 함수 통채로 추가
sub UnquoteHtmlForPageContent { my ($html) = @_; $html =~ s/&__GT__;/>/g; $html =~ s/&__LT__;/</g; $html =~ s/&__AMP__;/&/g; $html =~ s/\\ /\\\\\n/g; $html =~ s/\ /\\\n/g; return $html; }
다음 함수 통채로 추가
sub MakeLaTeX { my ($latex, $type) = @_; $latex = &UnquoteHtmlForPageContent($latex); # 그림파일의 이름은 텍스트를 해슁하여 결정 my $hash; my $hasMD5 = eval "require Digest::MD5;"; if ($hasMD5) { $hash = Digest::MD5::md5_base64($latex); } else { $hash = crypt($latex, $HashKey); } $hash =~ s/(\W)/uc sprintf "_%02x", ord($1)/eg; # 기본값 설정 my $hashimage = "$hash.png"; my $imgpath = ""; my $LatexDir = "$UploadDir/latex"; my $LatexUrl = "$UploadUrl/latex"; my $TemplateFile = "$DataDir/latex.template"; # 디렉토리 생성 &CreateDir($UploadDir); &CreateDir($LatexDir); if (-f "$LatexDir/$hashimage" && not -z "$LatexDir/$hashimage") { # 이미 생성되어 캐쉬에 있음 } else { # 새로 생성해야 됨 my $hashdir = "$TempDir/$hash"; my $DefaultTemplate = << 'EOT'; \documentclass[12pt]{amsart} % Your can use the desire symbol packages % Of course, MikTeX needs to be able to get the % package that you specify \usepackage{mathptmx,bm,calrsfs} % "sboxit" puts two marks on top and bottom of the math % equation for ImageMagick to cut out the image \def\sboxit#1{% \setbox0=\hbox{#1}\hbox{\vbox{\hsize=\wd0\hrule height1pt width2pt% \hbox{\vrule width0pt\kern0pt\vbox{% \vspace{1pt}\noindent\unhbox0\vspace{1pt}}% \kern1pt\vrule width0pt}\hrule height1pt width2pt}}} \mathchardef\gt="313E % type $a\gt b$ instead of $a > b$ \mathchardef\lt="313C % type $a\lt b$ instead of $a < b$ \pagestyle{empty} \begin{document} \thispagestyle{empty} % the first hbox make the depth of the equation right \sboxit{\hbox to 0pt{\phantom{g}}<math>} \end{document} EOT if (not -d $hashdir) { mkdir($hashdir,0775) or return "[Unable to create $hash dir]"; } if (not -f $TemplateFile) { &WriteStringToFile($TemplateFile, $DefaultTemplate); } my $template = &ReadFile($TemplateFile); $template =~ s/<math>/$latex/ige; my $pwd = `pwd`; $pwd =~ s/(.*)((\n|\r)*)?/$1/; chdir ($hashdir); # 원본 tex 생성 open (OUTFILE, ">srender.tex"); print OUTFILE $template; close OUTFILE; open SAVEOUT, ">&STDOUT"; open SAVEERR, ">&STDERR"; open STDOUT, ">hash.log"; open STDERR, ">&STDOUT"; # 그림 생성 qx(latex -interaction=nonstopmode srender.tex); qx(dvips srender.dvi); qx(convert -transparent "white" -density 100x100 -trim -shave 0x2 srender.ps $hashimage); close STDOUT; close STDERR; open STDOUT, ">&SAVEOUT"; open STDERR, ">&SAVEERR"; # upload 경로 그림 옮김 chdir($pwd); if (-f "$hashdir/$hashimage" && not -z "$hashdir/$hashimage") { my $png = &ReadFile("$hashdir/$hashimage"); &WriteStringToFile("$LatexDir/$hashimage", $png); } else { return "[Error retrieving image from $hashdir:$pwd]"; } unlink (glob("$hashdir/*")) or return "[[unlink fail]]"; rmdir ($hashdir) or return "[[rmdir fail]]"; } # IMG 태그 출력 if ($type eq "inline") { $imgpath = "<IMG border=0 vspace=0 hspace=0 align='middle' ". "src='$LatexUrl/$hashimage' ". "alt=\"\$$latex\$\">"; } elsif ($type eq "display") { $imgpath = "<br>". "<IMG border=0 vspace=15 hspace=40 align='middle' ". "src='$LatexUrl/$hashimage' ". "alt=\"$latex\">". "</br>"; } return $imgpath; }
ext1.74d - png 파일명을 결정하는 부분 개선. 특수 문자를 삭제하지 않고 아스키코드로 표현하게 함
ext1.74e - 1.74d 에서, 특수문자를 "%16진수"의 형태로 만들었더니 문제가 있어서, "_16진수"의 형태로 만들도록 함
ext2.10 - 서버에 설치하기 힘든 경우 /LaTeX플러그인을 사용할 수 있게 함
[여기]에 현재까지 작업된 결과를 볼 수 있습니다.
왕입니다요 !!!
LaTeX 변환을 위한 문법을 어떻게 해야 될지 고민 중입니다.
1) usemod 구현 $a<b$ - 문장 내에 삽입 $$a<b$$ - 별개의 줄로 LaTeX과 동일한 방식이라 LaTeX 코드를 그대로 쓸 수 있음. 그러나 $a<b$ 의 경우 "$"가 다른 의미로 쓰인 곳에서도 LaTeX변환이 이뤄질 경우가 많음 (ex. "$UploadDir, $UploadUrl 을 설정한다"와 같은 경우) 2) oddmuse 구현 $$a<b$$ - 문장 내에 삽입 \[a<b\] - 별개의 줄로 다른 데서 $$ 나 \[ 를 사용할 일이 거의 없기 때문에 오변환의 가능성이 적지만 LaTeX에서의 문법과 의미가 달라진다. 3) oddmuse 에서 별도 옵션 사용 $a<b$ - 문장 내에 삽입 $$a<b$$ - 별개의 줄로 \[a<b\] - 별개의 줄로 4) moniwiki 구현 $(공백)a<b$(공백) - 문장 내에 삽입 공백이 반드시 있어야 하기 때문에 1)에서와 같은 오변환의 가능성이 적어짐저는 지금부터 자잘한 수정에 들어갈테니 이 글 보시면 의견 좀 주세요. (근데 의견달라고 하면 왜 다들 조용히 계시는지? :-)
$$와 \[ 로 결정
뭔가 좀 부족한 게 있을 듯 합니다만 일단 여기까지 하고 마칩니다~