TikZ를 사용한 독립형 다이어그램?
저는 TikZ를 사용하여 LaTeX에서 다이어그램을 그린 다음 온라인에 놓을 이미지 파일로 분리하고 싶습니다. 제 생각에는 완성 된 .pdf 파일에서 이러한 다이어그램을 뜯어 내지 않고도 직접 이러한 다이어그램을 추출 할 수있는 방법이 있습니다. 어떻게할까요? (중요하다면 TeXnicCenter를 사용하고 있습니다.)
내 의견에 대한 후속 조치 : Cirkuit 은 다음 명령 시퀀스와 같은 것을 실행하여 TikZ 다이어그램을 이미지로 변환합니다.
pdflatex img.tex
pdftops -eps img.pdf
convert -density 300 img.eps img.png
다음 img.tex은이 템플릿을 따르는 LaTeX 파일입니다.
\documentclass{article}
\usepackage{tikz,amsmath,siunitx}
\usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,shadows,plotmarks}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\PreviewEnvironment{equation}
\PreviewEnvironment{equation*}
\newlength{\imagewidth}
\newlength{\imagescale}
\pagestyle{empty}
\thispagestyle{empty}
\begin{document}
\begin{tikzpicture}
% (your TikZ code goes here)
\end{tikzpicture}
\end{document}
Cirkuit 또는 유사한 편집기를 사용할 수 있거나 다이어그램을 해당 템플릿에 넣고 적절한 도구를 실행하는 스크립트를 직접 작성할 수 있다면 TikZ 코드를 PNG 이미지로 빠르게 변환 할 수 있습니다.
질문에 더 직접적으로 대답하기 위해 ... 아니요, 어떤 단계에서 PDF 파일 (또는 적어도 DVI)을 거치지 않고 TikZ 다이어그램 을 PNG로 직접 변환하는 방법을 모르겠습니다 .
다음과 같은 접근 방식을 권장합니다. tikz 그림을 별도의 파일에 넣고 'standalone'클래스를 사용하여 독립 실행 형으로 컴파일합니다. 다른 답변에 언급 된 '미리보기'패키지를 사용합니다. 주 문서에 그림을 포함하려면 먼저 '독립 실행 형' 패키지를 로드 하고 그림 파일에 \ input을 사용하십시오.
이렇게하면 여백없이 tikz 그림의 단일 PDF를 얻을 수 있습니다. 그런 다음 PDF-to-say PNG 변환기를 사용하여 PNG를 얻을 수 있습니다 (도면의 웹 게시에 권장 됨). SVG 형식은 벡터 형식이기 때문에 더 좋을 수 있지만 모든 브라우저가이를 표시 할 수있는 것은 아닙니다.
다음은 몇 가지 예제 코드입니다.
tikz 그림 파일 (예 : 'pic.tex') :
\documentclass{standalone}
\usepackage{tikz}
% all other packages and stuff you need for the picture
%
\begin{document}
\begin{tikzpicture}
% your picture code
\end{tikzpicture}
\end{document}
주요 문서 :
\documentclass{article} % or whatever class you are using
\usepackage{standalone}
\usepackage{tikz}
% All other packages required
\begin{document}
% Text text text
% somewhere where you want the tikz picture
\input{pic}
% Text text text
\end{document}
그런 다음 그림을 컴파일하고 변환합니다 (예 : ImageMagick 사용) (예 : Linux에서).
pdflatex pic
convert -density 600x600 pic.pdf -quality 90 -resize 800x600 pic.png
또는 SVG를 사용해보십시오.
convert pic.pdf pic.svg
Tikz 매뉴얼 섹션 "그래픽 외부화"를 참조하십시오. 이렇게하면 그래픽의 EPS 또는 PDF 버전을 만들 수 있습니다. EPS 파일을 사용하고 TIFF로 변환 한 다음 필요한 곳에 둘 수 있습니다.
나는 일반적으로 다음 줄을 따라 무언가를 사용하고 있습니다.
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
%\setlength\PreviewBorder{2mm} % use to add a border around the image
\usepackage{tikz}
\begin{document}
\begin{preview}
\begin{tikzpicture}
\shade (0,0) circle(2); % background
\draw (0,0) circle(2); % rim
\draw (.75,1) circle(.5); % right eye
\fill (.66,.9) circle(.25); % right pupil
\draw (-.75,1) circle(.5); % left eye
\fill (-.66,.9) circle(.25);% left pupil
\fill (.2,0) circle (.1); % right nostril
\fill (-.2,0) circle (.1); % left nostril
\draw (-135:1) arc (-135:-45:1) -- cycle; % mouth
\end{tikzpicture}
\end{preview}
\end{document}
생성 된 pdf 파일에는 독립형 TikZ 사진이 포함되어 있습니다. 다른 파일 형식으로 변환하려면 Gimp로 열기 만하면됩니다.
I use this to Makefile rule create PNG files and thumbnails from .tex files that contain one tikzpicture each. It works similar to the creation of images at TeXample.net:
%.png: %.tex
@sed 's/^\\begin{document}/\
\\pgfrealjobname{dummy}\\begin{document}\\beginpgfgraphicnamed{example}/' $< | \
sed 's/^\\end{document}/\\endpgfgraphicnamed\\end{document}/' > example.tex ; \
pdflatex --jobname=example example.tex ; \
gs -dNOPAUSE -r120 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sDEVICE=png16m \
-sOutputFile=$@ -dBATCH example.pdf ; \
convert -thumbnail 200 $@ $(addsuffix .thumb.png, $(basename $@)) ; \
mv example.pdf $(addsuffix .pdf, $(basename $<)) ; rm example.*
ghostview (gs) can probably be replaced by convert and you can replace example with another tempfile prefix.
Windows: Just to be completely explicit for noobs like me
Use the prewiew package as Habi suggested in the above in your latex code to remove margins.
Install MIktex and Inkscape and use the following bat file:
cd = "C:\Path to tex"
pdflatex input-file-name.tex
"C:\Program Files (x86)\Inkscape\inkscape.exe" input-file-name.pdf --export-plain-svg=output-file-name.svg
참고URL : https://stackoverflow.com/questions/2701902/standalone-diagrams-with-tikz
'program story' 카테고리의 다른 글
| RequireJS : "requirejs"와 "require"함수의 차이점 (0) | 2020.10.17 |
|---|---|
| C # Generics는 위임 형식 제약 조건을 허용하지 않습니다. (0) | 2020.10.17 |
| 제네릭 클래스의 정적 멤버가 특정 인스턴스에 연결되어 있습니까? (0) | 2020.10.17 |
| 좋은 무료 소형 Python 웹 호스트가 있습니까? (0) | 2020.10.17 |
| Bootstrap 3 RC 1의 자동 완성 JavaScript 모듈은 어디에 있습니까? (0) | 2020.10.17 |