emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-e-latex: Tables get correct amount of vertical space
@ 2012-11-13 14:29 Myles English
  2012-11-13 14:54 ` Sebastien Vauban
  0 siblings, 1 reply; 11+ messages in thread
From: Myles English @ 2012-11-13 14:29 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

This patch replaces every occurence of the \begin{center} environment
with \centering in the file contrib/lisp/org-e-latex.el.  I have tested
the export of a basic table and it works but not sure if all the
replacements are correct.

( BTW, this issue came to light using the nag package like this:
\RequirePackage[l2tabu, orthodox]{nag} )

Myles


From 54ae2245978fa755cd5daa483616ffdfa3e5ed0f Mon Sep 17 00:00:00 2001
From: Myles English <mylesenglish@gmail.com>
Date: Tue, 13 Nov 2012 14:14:56 +0000
Subject: [PATCH] org-e-latex:  Tables get correct amount of vertical space

* contrib/lisp/org-e-latex.el: Replaced \begin{center} ..\end{center}
  environments with \centering declarations.

Using both \begin{table} and \being{center} environments leads to double
the vertical space around the float, whereas \centering adds none.

TINYCHANGE
---
 contrib/lisp/org-e-latex.el | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el
index 165beb3..c268c2c 100644
--- a/contrib/lisp/org-e-latex.el
+++ b/contrib/lisp/org-e-latex.el
@@ -550,14 +550,13 @@ in order to mimic default behaviour:
 	  \(when tags
             \(format \"\\\\hfill{}\\\\textsc{:%s:}\"
                     \(mapconcat 'identity tags \":\")))))
-    \(format (concat \"\\\\begin{center}\\n\"
+    \(format (concat \"\\\\centering\\n\"
 		    \"\\\\fbox{\\n\"
 		    \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
 		    \"%s\\n\\n\"
 		    \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
 		    \"%s\"
-		    \"\\\\end{minipage}}\"
-		    \"\\\\end{center}\")
+		    \"\\\\end{minipage}}\")
 	    full-title contents))"
   :group 'org-export-e-latex
   :type 'function)
@@ -1086,7 +1085,7 @@ CONTENTS holds the contents of the center block.  INFO is a plist
 holding contextual information."
   (org-e-latex--wrap-label
    center-block
-   (format "\\begin{center}\n%s\\end{center}" contents)))
+   (format "\\centering\n%s" contents)))
 
 
 ;;;; Clock
@@ -1508,15 +1507,14 @@ holding contextual information."
 	       title
 	       (when tags (format "\\hfill{}\\textsc{:%s:}"
 				  (mapconcat 'identity tags ":"))))))
-	 (format (concat "\\begin{center}\n"
+	 (format (concat "\\centering\n"
 			 "\\fbox{\n"
 			 "\\begin{minipage}[c]{.6\\textwidth}\n"
 			 "%s\n\n"
 			 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
 			 "%s"
 			 "\\end{minipage}\n"
-			 "}\n"
-			 "\\end{center}")
+			 "}")
 		 full-title contents))))))
 
 
@@ -2302,14 +2300,13 @@ This function assumes TABLE has `org' as its `:type' attribute."
 		  (concat
 		   (format "\\begin{%s}%s\n" float-env placement)
 		   (if org-e-latex-table-caption-above caption "")))
-		(when org-e-latex-tables-centered "\\begin{center}\n")
+		(when org-e-latex-tables-centered "\\centering\n")
 		(format "\\begin{%s}%s{%s}\n%s\\end{%s}"
 			table-env
 			(if width (format "{%s}" width) "")
 			alignment
 			contents
 			table-env)
-		(when org-e-latex-tables-centered "\n\\end{center}")
 		(when float-env
 		  (concat (if org-e-latex-table-caption-above "" caption)
 			  (format "\n\\end{%s}" float-env))))))))
@@ -2351,7 +2348,7 @@ attribute."
 	    (unless (= n 2)
 	      (setq output (replace-match "" nil nil output)))))))
     (if (not org-e-latex-tables-centered) output
-      (format "\\begin{center}\n%s\n\\end{center}" output))))
+      (format "\\centering\n%s" output))))
 
 
 ;;;; Table Cell
-- 
1.8.0

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 14:29 [PATCH] org-e-latex: Tables get correct amount of vertical space Myles English
@ 2012-11-13 14:54 ` Sebastien Vauban
  2012-11-13 15:05   ` Myles English
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastien Vauban @ 2012-11-13 14:54 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Myles,

Myles English wrote:
> This patch replaces every occurence of the \begin{center} environment
> with \centering in the file contrib/lisp/org-e-latex.el.
> ...
> -   (format "\\begin{center}\n%s\\end{center}" contents)))
> +   (format "\\centering\n%s" contents)))

Wouldn't you have to replace

  \begin{center}
    ...
  \end{center}

by

  {\centering
    ...
  }

?  That is, add a group around?

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 14:54 ` Sebastien Vauban
@ 2012-11-13 15:05   ` Myles English
  2012-11-13 15:56     ` Nick Dokos
  0 siblings, 1 reply; 11+ messages in thread
From: Myles English @ 2012-11-13 15:05 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode


Hi Seb,

Sebastien Vauban writes:

> Hi Myles,
>
> Myles English wrote:
>> This patch replaces every occurence of the \begin{center} environment
>> with \centering in the file contrib/lisp/org-e-latex.el.
>> ...
>> -   (format "\\begin{center}\n%s\\end{center}" contents)))
>> +   (format "\\centering\n%s" contents)))
>
> Wouldn't you have to replace
>
>   \begin{center}
>     ...
>   \end{center}
>
> by
>
>   {\centering
>     ...
>   }
>
> ?  That is, add a group around?

I don't think so, at least I have not come across that usage, and it
seems to work without.  Do you know different?

Myles

>
> Best regards,
>   Seb

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 15:05   ` Myles English
@ 2012-11-13 15:56     ` Nick Dokos
  2012-11-13 16:15       ` Sebastien Vauban
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Dokos @ 2012-11-13 15:56 UTC (permalink / raw)
  To: Myles English; +Cc: Sebastien Vauban, emacs-orgmode

Myles English <mylesenglish@gmail.com> wrote:

> 
> Hi Seb,
> 
> Sebastien Vauban writes:
> 
> > Hi Myles,
> >
> > Myles English wrote:
> >> This patch replaces every occurence of the \begin{center} environment
> >> with \centering in the file contrib/lisp/org-e-latex.el.
> >> ...
> >> -   (format "\\begin{center}\n%s\\end{center}" contents)))
> >> +   (format "\\centering\n%s" contents)))
> >
> > Wouldn't you have to replace
> >
> >   \begin{center}
> >     ...
> >   \end{center}
> >
> > by
> >
> >   {\centering
> >     ...
> >   }
> >
> > ?  That is, add a group around?
> 
> I don't think so, at least I have not come across that usage, and it
> seems to work without.  Do you know different?
> 

If a \centering occurs at top-level in a latex document,
then *everything* after it will be centered: it's a declaration that
remains in force for the current group (which is the rest of the
document if it occurs at top-level).

\begin{center}...\end{center} is essentially {\centering ...} except
that it also starts a new paragraph.

It's not clear to me at least, that wholesale replacement is the correct
thing to do: it needs to be looked at on a case-by-case basis I think.

Nick

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 15:56     ` Nick Dokos
@ 2012-11-13 16:15       ` Sebastien Vauban
  2012-11-13 16:20         ` Nick Dokos
  2012-11-13 21:31         ` Myles English
  0 siblings, 2 replies; 11+ messages in thread
From: Sebastien Vauban @ 2012-11-13 16:15 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Myles and Nick,

Nick Dokos wrote:
> Myles English <mylesenglish-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> Sebastien Vauban writes:
>> > Myles English wrote:
>> >> This patch replaces every occurence of the \begin{center} environment
>> >> with \centering in the file contrib/lisp/org-e-latex.el.
>> >> ...
>> >> -   (format "\\begin{center}\n%s\\end{center}" contents)))
>> >> +   (format "\\centering\n%s" contents)))
>> >
>> > Wouldn't you have to replace
>> >
>> >   \begin{center}
>> >     ...
>> >   \end{center}
>> >
>> > by
>> >
>> >   {\centering
>> >     ...
>> >   }
>> >
>> > ?  That is, add a group around?
>> 
>> I don't think so, at least I have not come across that usage, and it
>> seems to work without.  Do you know different?
>
> If a \centering occurs at top-level in a latex document,
> then *everything* after it will be centered: it's a declaration that
> remains in force for the current group (which is the rest of the
> document if it occurs at top-level).

As confirmed by Nick, \centering just changes the layout for ever... up to the
end of the document.

Why does it work?  I guess because there are grouping commands inserted by Org
at other places, that stop the propagation of the centering that far... But
it's dangerous to count on them, IMHO.

> \begin{center}...\end{center} is essentially {\centering ...} except
> that it also starts a new paragraph.
>
> It's not clear to me at least, that wholesale replacement is the correct
> thing to do: it needs to be looked at on a case-by-case basis I think.

I think that's a safe replacement (_with_ the grouping), and with something I
forgot about (well seen Nick!): the \par.

See, for example,
https://groups.google.com/forum/?fromgroups=#!topic/fr.comp.text.tex/0s4WfsIfmy8
for the answer of Manuel Pégourié-Gonnard, one reference wrt LaTeX questions:

  "replace the environment by {\centering ... \par}"

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 16:15       ` Sebastien Vauban
@ 2012-11-13 16:20         ` Nick Dokos
  2012-11-13 16:32           ` Nick Dokos
  2012-11-13 21:31         ` Myles English
  1 sibling, 1 reply; 11+ messages in thread
From: Nick Dokos @ 2012-11-13 16:20 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode

Sebastien Vauban <wxhgmqzgwmuf@spammotel.com> wrote:

> I think that's a safe replacement (_with_ the grouping), and with something I
> forgot about (well seen Nick!): the \par.
> 
> See, for example,
> https://groups.google.com/forum/?fromgroups=#!topic/fr.comp.text.tex/0s4WfsIfmy8
> for the answer of Manuel Pégourié-Gonnard, one reference wrt LaTeX questions:
> 
>   "replace the environment by {\centering ... \par}"
> 

I think I read the whole thread but I'm still not clear on why
the change is needed. What goes awry with the environment instead
of the declaration?

Nick

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 16:20         ` Nick Dokos
@ 2012-11-13 16:32           ` Nick Dokos
  2012-11-14  8:44             ` Sebastien Vauban
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Dokos @ 2012-11-13 16:32 UTC (permalink / raw)
  Cc: Sebastien Vauban, emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> wrote:

> 
> I think I read the whole thread but I'm still not clear on why
> the change is needed. What goes awry with the environment instead
> of the declaration?
> 

Never mind - I didn't read the whole thread.

Nick

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 16:15       ` Sebastien Vauban
  2012-11-13 16:20         ` Nick Dokos
@ 2012-11-13 21:31         ` Myles English
  2012-11-14 14:03           ` Nicolas Goaziou
  1 sibling, 1 reply; 11+ messages in thread
From: Myles English @ 2012-11-13 21:31 UTC (permalink / raw)
  To: Sebastien Vauban, Nick Dokos; +Cc: emacs-orgmode



Sebastien Vauban writes:

> Hi Myles and Nick,
>
> Nick Dokos wrote:
>> Myles English <mylesenglish@gmail.com> wrote:
>>> Sebastien Vauban writes:
>>> > Myles English wrote:
>>> >> This patch replaces every occurence of the \begin{center} environment
>>> >> with \centering in the file contrib/lisp/org-e-latex.el.
>>> >> ...
>>> >> -   (format "\\begin{center}\n%s\\end{center}" contents)))
>>> >> +   (format "\\centering\n%s" contents)))
>>> >
>>> > Wouldn't you have to replace
>>> >
>>> >   \begin{center}
>>> >     ...
>>> >   \end{center}
>>> >
>>> > by
>>> >
>>> >   {\centering
>>> >     ...
>>> >   }
>>> >
>>> > ?  That is, add a group around?
>>> 
>>> I don't think so, at least I have not come across that usage, and it
>>> seems to work without.  Do you know different?
>>
>> If a \centering occurs at top-level in a latex document,
>> then *everything* after it will be centered: it's a declaration that
>> remains in force for the current group (which is the rest of the
>> document if it occurs at top-level).
>
> As confirmed by Nick, \centering just changes the layout for ever... up to the
> end of the document.
>
> Why does it work?  I guess because there are grouping commands inserted by Org
> at other places, that stop the propagation of the centering that far... But
> it's dangerous to count on them, IMHO.
>
>> \begin{center}...\end{center} is essentially {\centering ...} except
>> that it also starts a new paragraph.

From within a figure or table environment, that new paragraph shows up
as uneeded vertical space, see the example I give lower down.

>> 
>>
>> It's not clear to me at least, that wholesale replacement is the correct
>> thing to do: it needs to be looked at on a case-by-case basis I
>> think.

Nick, I think you are right about this, the modified patch at the end of
this email makes only the replacements that are necessary just to
replace the center environment within table blocks.

The other \begin{center}'s in the org-e-latex.el file may be changed
some other time, if needed.

> I think that's a safe replacement (_with_ the grouping), and with something I
> forgot about (well seen Nick!): the \par.

I don't think the grouping is necessary because the implied group will
be closed when the table environment is ended.  Likewise, I don't think
the \par is necessary.

If you compile this this latex it illustrates the problem, and the
solution:

%______________________________begin example.tex_______________
\documentclass[11pt]{article}
\usepackage{float}

\begin{document}

Before.-------------------------------

\begin{table}[htb]
\caption{\label{tab:progress}Summary}
\begin{center}
\begin{tabular}{ll}
A & B\\
\end{tabular}
\end{center}
\end{table}

After.--------------------------------

Before.-------------------------------

\begin{table}[htb]
\caption{\label{tab:progress}Summary}
\centering
\begin{tabular}{ll}
A & B\\
\end{tabular}
\end{table}

After.-------------------------------
\end{document}
%______________________________end example.tex_______________

> See, for example,
> https://groups.google.com/forum/?fromgroups=#!topic/fr.comp.text.tex/0s4WfsIfmy8
> for the answer of Manuel Pégourié-Gonnard, one reference wrt LaTeX
> questions:

My French, and my browser apparently, is not good enough to understand
that thread.  Sorry.  Please translate if it is still relevant to this
discussion.

>
>   "replace the environment by {\centering ... \par}"

[answered above]

>
> Best regards,
>   Seb

Myles


From 51686ada4cb2560eb5dfb6b445af547eccff8bff Mon Sep 17 00:00:00 2001
From: Myles English <mylesenglish@gmail.com>
Date: Tue, 13 Nov 2012 21:04:16 +0000
Subject: [PATCH] org-e-latex:  Tables get correct amount of vertical space

* contrib/lisp/org-e-latex.el: Replaced a set of \begin{center}
  and \end{center} environment markers with a \centering
  declaration.

Using both \begin{table} and \being{center} environments leads to double
the vertical space around the float, whereas \centering adds none.

TINYCHANGE
---
 contrib/lisp/org-e-latex.el | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el
index 165beb3..5635c6a 100644
--- a/contrib/lisp/org-e-latex.el
+++ b/contrib/lisp/org-e-latex.el
@@ -2302,14 +2302,13 @@ This function assumes TABLE has `org' as its `:type' attribute."
 		  (concat
 		   (format "\\begin{%s}%s\n" float-env placement)
 		   (if org-e-latex-table-caption-above caption "")))
-		(when org-e-latex-tables-centered "\\begin{center}\n")
+		(when org-e-latex-tables-centered "\\centering\n")
 		(format "\\begin{%s}%s{%s}\n%s\\end{%s}"
 			table-env
 			(if width (format "{%s}" width) "")
 			alignment
 			contents
 			table-env)
-		(when org-e-latex-tables-centered "\n\\end{center}")
 		(when float-env
 		  (concat (if org-e-latex-table-caption-above "" caption)
 			  (format "\n\\end{%s}" float-env))))))))
-- 
1.8.0

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 16:32           ` Nick Dokos
@ 2012-11-14  8:44             ` Sebastien Vauban
  2012-11-14  9:40               ` Myles English
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastien Vauban @ 2012-11-14  8:44 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Nick,

Nick Dokos wrote:
> Nick Dokos <nicholas.dokos-VXdhtT5mjnY@public.gmane.org> wrote:
>> 
>> I think I read the whole thread but I'm still not clear on why
>> the change is needed. What goes awry with the environment instead
>> of the declaration?
>
> Never mind - I didn't read the whole thread.

To summarize:

- \begin{center}...\end{center} adds (undesired) vertical space
- replacing by {\centering...\par} is the solution against that.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-14  8:44             ` Sebastien Vauban
@ 2012-11-14  9:40               ` Myles English
  0 siblings, 0 replies; 11+ messages in thread
From: Myles English @ 2012-11-14  9:40 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode


Sebastien Vauban writes:

> Hi Nick,
>
> Nick Dokos wrote:
>> Nick Dokos <nicholas.dokos@hp.com> wrote:
>>> 
>>> I think I read the whole thread but I'm still not clear on why
>>> the change is needed. What goes awry with the environment instead
>>> of the declaration?
>>
>> Never mind - I didn't read the whole thread.
>
> To summarize:
>
> - \begin{center}...\end{center} adds (undesired) vertical space
> - replacing by {\centering...\par} is the solution against that.

Or just \centering when contained in a figure or table environment
block so making the {...\par} unecessary.

Myles

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

* Re: [PATCH] org-e-latex: Tables get correct amount of vertical space
  2012-11-13 21:31         ` Myles English
@ 2012-11-14 14:03           ` Nicolas Goaziou
  0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Goaziou @ 2012-11-14 14:03 UTC (permalink / raw)
  To: Myles English; +Cc: Sebastien Vauban, Nick Dokos, emacs-orgmode

Hello,

Myles English <mylesenglish@gmail.com> writes:

> Nick, I think you are right about this, the modified patch at the end of
> this email makes only the replacements that are necessary just to
> replace the center environment within table blocks.
>
> The other \begin{center}'s in the org-e-latex.el file may be changed
> some other time, if needed.

Applied. Thank you.


Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2012-11-14 14:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-13 14:29 [PATCH] org-e-latex: Tables get correct amount of vertical space Myles English
2012-11-13 14:54 ` Sebastien Vauban
2012-11-13 15:05   ` Myles English
2012-11-13 15:56     ` Nick Dokos
2012-11-13 16:15       ` Sebastien Vauban
2012-11-13 16:20         ` Nick Dokos
2012-11-13 16:32           ` Nick Dokos
2012-11-14  8:44             ` Sebastien Vauban
2012-11-14  9:40               ` Myles English
2012-11-13 21:31         ` Myles English
2012-11-14 14:03           ` Nicolas Goaziou

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).