emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Preview tikz in org-mode (reduce margins of produced images)
@ 2014-05-16  8:34 Leu Zhe
  2014-05-16 16:42 ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Leu Zhe @ 2014-05-16  8:34 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

Hi, everyone!

I always use org-preview-latex-fragment command to preview the LaTeX code,
which is awesome.
It can effectively crop and suit the size of produced png to the content.

However, recently I start to preview some tikz code.
I can greatly produce the good results except one problem:
The preview can never reduce the spare margin of the produced images, which
left large blank space there. However, when I preview other LaTeX code
after deleting tikz preamble, everything is fine.

So is there anyone who has some idea to reduce the large margins?


Leu

[-- Attachment #2: Type: text/html, Size: 736 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Preview tikz in org-mode (reduce margins of produced images)
  2014-05-16  8:34 Leu Zhe
@ 2014-05-16 16:42 ` Nick Dokos
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Dokos @ 2014-05-16 16:42 UTC (permalink / raw)
  To: emacs-orgmode

Leu Zhe <lzhes43@gmail.com> writes:

> Hi, everyone!
>
> I always use org-preview-latex-fragment command to preview the LaTeX
> code, which is awesome.  It can effectively crop and suit the size of
> produced png to the content.
>
> However, recently I start to preview some tikz code.   I can greatly
> produce the good results except one problem: The preview can never
> reduce the spare margin of the produced images, which left large blank
> space there. However, when I preview other LaTeX code after deleting
> tikz preamble, everything is fine.
>
> So is there anyone who has some idea to reduce the large margins?
>

It helps if you provide a small example: otherwise, even if one is
willing to take a stab at it, one has to create one from scratch. Given
that just about all of us have limited time, that reduces the
probability that you will get an answer.

Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Preview tikz in org-mode (reduce margins of produced images)
@ 2014-05-17  4:52 Leu Zhe
  2014-05-17 15:28 ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Leu Zhe @ 2014-05-17  4:52 UTC (permalink / raw)
  To: ndokos, emacs-orgmode@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 97 bytes --]

Hi ndokos,

Thanks for you advice.
I added a attachment which matches my problem.

Best regards!

[-- Attachment #1.2: Type: text/html, Size: 193 bytes --]

[-- Attachment #2: test.org --]
[-- Type: application/octet-stream, Size: 4464 bytes --]

Content-Type: text/enriched
Text-Width: 70

#+LATEX_HEADER: \usepackage{tikz}
#+LATEX_HEADER: \usepackage[siunitx]{circuitikz}


<x-color><param>dodger blue</param>* A tikz preview test in org-mode

</x-color>

<x-bg-color><param>#EAEAFF</param><x-color><param>#008ED1</param>#+begin_src latex
</x-color></x-bg-color><x-color><param>#859900</param>\begin</x-color>{<x-color><param>#268bd2</param>tikzpicture</x-color>}[scale=2]
  <x-color><param>#859900</param>\draw</x-color>[color=black, thick]
	(0,0) to [short,o-] (6,0){} <x-color><param>#93a1a1</param>% Baseline for connection to ground
</x-color>	<x-color><param>#93a1a1</param>% Input and ground
</x-color>	(0,1) node[]{<x-color><param>#859900</param>\large</x-color>{<x-color><param>#859900</param>\textbf</x-color>{<bold>INPUT</bold>}}}
	<x-color><param>#93a1a1</param>% Connection of passive components
</x-color>	(5,0) node[ground]{} node[circ](4.5,0){}
	(0,2) to [pC, l=$C_1$, o-] (0.5,2)
	to [R,l=$R_1$,](1.5,2)
	to node[short]{}(2.6,2)
	(1.5,2) to [C, l=$C_2$, *-] (1.5,3) -| (5,3)
	(2.2,2) to [R, l=$R_2$, *-*] (2.2,3)
	(2.2,3) to [pC, l=$C_3$, *-] (2.2,5) -| (3,5)
	<x-color><param>#93a1a1</param>% Transistor Bipolar Q1
</x-color>	(3,0) to [R,l=$R_5$,-*] (3,1.5)
	to [Tnpn,n=npn1] (3,2.5)
	(npn1.E) node[right=3mm, above=5mm]{$Q_1$} <x-color><param>#93a1a1</param>% Labelling the NPN transistor
</x-color>	(4,0) to [pC, l_=$C_4$, *-] (4, 1.5)--(3,1.5)
	(2.2,0) to [vR, l=$R_3$, *-*] (2.2,2)
	(3,2.5) to node[short]{}(3,3)
	(3,5) to [pR, n=pot1, l_=$R_4$, *-] (3,3)
	(3,5) to [R, l=$R_6$, *-] (5,5)
	to [short,*-o](5,5.5) node[right]{$V_S=40 V$}
	<x-color><param>#93a1a1</param>% Mosfet Transistors
</x-color>	(5,3) to [Tnigfetd,n=mos1] (5,5)
	(mos1.B) node[anchor=west]{$Q_2$} <x-color><param>#93a1a1</param>% Labelling MOSFET Q2 Transistor
</x-color>	(pot1.wiper)  to [R, l=$R_7$] (4.5,4) -| (mos1.G)
	(5,1.5) to [Tpigfetd,n=mos2] (5,2.5)
	(5,0) to (mos2.S)
	(3,2.5) to [R, l=$R_8$, *-] (4.5,2.5)
	-| (mos2.G)
	(mos2.B) node[anchor=west]{$Q_3$} <x-color><param>#93a1a1</param>% Labelling MOSFET Q3 Transistor
</x-color>	<x-color><param>#93a1a1</param>% Output
</x-color>	(6,3) to [pC, l=$C_5$,-*](5,3)
	(6,3) to [short,-o] (6,2){}
	(mos1.S)--(mos2.D)
	(6,0) to [short,-o] (6,1){} node[above=7mm]{<x-color><param>#859900</param>\large</x-color>{<x-color><param>#859900</param>\textbf</x-color>{<bold>SPEAKER</bold>}}}
	;
<x-color><param>#859900</param>\end</x-color>{<x-color><param>#268bd2</param>tikzpicture</x-color>}

<x-bg-color><param>#EAEAFF</param><x-color><param>#008ED1</param>#+end_src

</x-color></x-bg-color>

with tikz package in the premeable, even I preview <x-color><param>SaddleBrown</param>$$\mu$$</x-color>, it would produce large margins.


The <x-color><param>#b58900</param>=org-format-latex-header=</x-color> is set as below in .

<x-bg-color><param>#EAEAFF</param><x-color><param>#008ED1</param>#+begin_src emacs-lisp

</x-color></x-bg-color>(custom-set-variables
 '(org-format-latex-header <x-color><param>#2aa198</param>"\\documentclass{article}
\\usepackage[usenames]{color}
\\usepackage[allowlitunits]{siunitx}
\\usepackage{booktabs}
\\usepackage{array}
%\\usepackage{tikz}
%\\usetikzlibrary{calc}
\\usepackage{multirow}
\\usepackage{threeparttable}
%\\usepackage[active, float]{preview}
%\\PreviewEnvironment{tikzpicture}
\\usepackage[labelsep=period]{caption}
\\usepackage[cm-default,no-math]{fontspec}
\\defaultfontfeatures{Mapping=tex-text}
\\setmainfont{Times New Roman}
\\setsansfont{Arial}
\\usepackage{mathspec}
\\setmathfont(Digits){Times New Roman}
\\setmathfont(Latin){Times New Roman}
\\usepackage{xeCJK}
\\setCJKmainfont[BoldFont={IPAGothic}]{IPAMincho}
\\setCJKsansfont{msgothic.ttc}
\\pagestyle{empty}             % do not remove
% The settings below are copied from fullpage.sty
\\setlength{\\textwidth}{\\paperwidth}
\\addtolength{\\textwidth}{-3cm}
\\setlength{\\oddsidemargin}{1.5cm}
\\addtolength{\\oddsidemargin}{-2.54cm}
\\setlength{\\evensidemargin}{\\oddsidemargin}
\\setlength{\\textheight}{\\paperheight}
\\addtolength{\\textheight}{-\\headheight}
\\addtolength{\\textheight}{-\\headsep}
\\addtolength{\\textheight}{-\\footskip}
\\addtolength{\\textheight}{-3cm}
\\setlength{\\topmargin}{1.5cm}
\\addtolength{\\topmargin}{-2.54cm}"</x-color>))
<x-bg-color><param>#EAEAFF</param><x-color><param>#008ED1</param>#+end_src</x-color></x-bg-color>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Preview tikz in org-mode (reduce margins of produced images)
  2014-05-17  4:52 Preview tikz in org-mode (reduce margins of produced images) Leu Zhe
@ 2014-05-17 15:28 ` Nick Dokos
  2014-05-21  1:59   ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2014-05-17 15:28 UTC (permalink / raw)
  To: emacs-orgmode

Leu Zhe <lzhes43@gmail.com> writes:

> Hi ndokos,
>
> Thanks for you advice. 
> I added a attachment which matches my problem.
>
> Best regards!
>
>
> Content-Type: text/enriched
> Text-Width: 70
>
> #+LATEX_HEADER: \usepackage{tikz}
> #+LATEX_HEADER: \usepackage[siunitx]{circuitikz}
>
>
> <x-color><param>dodger blue</param>* A tikz preview test in org-mode
>
> </x-color>
> ...

Unfortunately, you seem to have attached it as text/enriched and it is
messed up. Can you please attach it as text/plain?

Thanks!
-- 
Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Preview tikz in org-mode (reduce margins of produced images)
  2014-05-17 15:28 ` Nick Dokos
@ 2014-05-21  1:59   ` Bastien
  2014-05-21  4:42     ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien @ 2014-05-21  1:59 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 193 bytes --]

Nick Dokos <ndokos@gmail.com> writes:

> Unfortunately, you seem to have attached it as text/enriched and it is
> messed up. Can you please attach it as text/plain?

I attach it just in case.


[-- Attachment #2: test.org --]
[-- Type: application/vnd.lotus-organizer, Size: 4464 bytes --]

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Preview tikz in org-mode (reduce margins of produced images)
  2014-05-21  1:59   ` Bastien
@ 2014-05-21  4:42     ` Nick Dokos
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Dokos @ 2014-05-21  4:42 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@gnu.org> writes:

> Nick Dokos <ndokos@gmail.com> writes:
>
>> Unfortunately, you seem to have attached it as text/enriched and it is
>> messed up. Can you please attach it as text/plain?
>
> I attach it just in case.

Didn't know about enriched-mode - thanks!

But back to the original question: with the redefined
org-format-latex-header, I get errors (probably because the preview is
produced by running latex, whereas the redefined header seems to require
xetex). Without the redefined header, I get a preview which does *not*
have large margins. So the header is probably the culprit: I would start
deleting things from it, until the problem disappears. In particular,
the fullpage.sty settings look suspicious to me. Maybe somebody who has
set up previews with xe(la)tex can provide a more helpful answer
(doesn't that require code changes to org?)

-- 
Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Preview tikz in org-mode (reduce margins of produced images)
@ 2014-05-21  6:22 Leu Zhe
  2014-05-21  7:32 ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: Leu Zhe @ 2014-05-21  6:22 UTC (permalink / raw)
  To: Nick Dokos, emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 356 bytes --]

Hi Nick,

Thanks you for your help.

Finally I found a solution by referring the examples in texample.net.
I just replaced the \documentclass{article} to
 documentclass[varwidth]{standalone},
then it works perfectly.

I am not familiar enriched-mode, too.
It is also very strange that why i can not receive the email in my gmail...

Thank you anyway.

Leu

[-- Attachment #2: Type: text/html, Size: 587 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Preview tikz in org-mode (reduce margins of produced images)
  2014-05-21  6:22 Leu Zhe
@ 2014-05-21  7:32 ` Bastien
  0 siblings, 0 replies; 8+ messages in thread
From: Bastien @ 2014-05-21  7:32 UTC (permalink / raw)
  To: Leu Zhe; +Cc: Nick Dokos, emacs-orgmode@gnu.org

Hi Leu,

Leu Zhe <lzhes43@gmail.com> writes:

> I just replaced the \documentclass{article} to  documentclass
> [varwidth]{standalone},
> then it works perfectly.

Thanks for sharing this trick, hard to find, so even more valuable
when made public.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-05-21  7:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-17  4:52 Preview tikz in org-mode (reduce margins of produced images) Leu Zhe
2014-05-17 15:28 ` Nick Dokos
2014-05-21  1:59   ` Bastien
2014-05-21  4:42     ` Nick Dokos
  -- strict thread matches above, loose matches on Subject: below --
2014-05-21  6:22 Leu Zhe
2014-05-21  7:32 ` Bastien
2014-05-16  8:34 Leu Zhe
2014-05-16 16:42 ` Nick Dokos

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).