Vim Tips Wiki
Register
(Can the colon be omitted?)
(Comment added.)
Tag: Visual edit
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{TipNew
  +
|id=1610
  +
|previous=1609
  +
|next=1611
  +
|created=2008
  +
|complexity=basic
  +
|author=
  +
|version=7.0
  +
|subpage=/200811
  +
|category1=LaTeX
  +
|category2=
  +
}}
 
Typesetting LaTeX tables is time consuming and can get very complicated. It is, however, very easy to use the Perl [http://search.cpan.org/dist/LaTeX-Table/ LaTeX::Table] module from within Vim. Install the module with:
 
Typesetting LaTeX tables is time consuming and can get very complicated. It is, however, very easy to use the Perl [http://search.cpan.org/dist/LaTeX-Table/ LaTeX::Table] module from within Vim. Install the module with:
 
 
<pre>
 
<pre>
 
$ cpan LaTeX::Table
 
$ cpan LaTeX::Table
 
</pre>
 
</pre>
   
Then for example, type the following code in Vim and select the lines in VISUAL LINE mode:
+
Then for example, enter the following into a buffer:
 
<pre>
 
<pre>
 
theme=NYC;caption_top=1;caption=Bla
 
theme=NYC;caption_top=1;caption=Bla
 
Animal & Description & Price
 
Animal & Description & Price
Gnat & per gram & 13.65
+
Gnat & per gram & 13.65
& each & 0.02
+
& each & 0.02
 
Gnu & stuffed & 92.59
 
Gnu & stuffed & 92.59
 
</pre>
 
</pre>
   
Now type '''":!ltpretty"'''. The text is then replaced with the following LaTeX code:
+
Now visually select the lines (for example, <code>ggVG</code>), and enter the command <code>!ltpretty</code> to filter the text through the <code>ltpretty</code> script. The lines are replaced with the following LaTeX code:
 
 
<pre>
 
<pre>
% theme=NYC;caption_top=1;caption=Bla
+
% theme=NYC;caption_top=1;caption=Bla
 
% Animal & Description & Price
 
% Animal & Description & Price
 
% Gnat & per gram & 13.65
 
% Gnat & per gram & 13.65
Line 40: Line 50:
 
</pre>
 
</pre>
   
[[Category:LaTeX]]
 
 
==Comments==
 
==Comments==
  +
A similar alternative is the ViLaTaC script that can be downloaded from https://github.com/tannhuber/vilatac. It provides individual column formatting with a very simple syntax. However, it is intended for publishing. Thus, colorful themes are not supported.
Thanks for the new tip. Do you need the colon in the <tt>:!ltpretty</tt> command? I would have thought that after selecting some lines, just <tt>!ltpretty</tt> would be sufficient. See [[VimTip374|374 Use filter commands to process text]]. --[[User:JohnBeckett|JohnBeckett]] 03:39, 24 November 2008 (UTC)
 
 
----
 

Latest revision as of 11:09, 20 May 2014

Tip 1610 Printable Monobook Previous Next

created 2008 · complexity basic · version 7.0


Typesetting LaTeX tables is time consuming and can get very complicated. It is, however, very easy to use the Perl LaTeX::Table module from within Vim. Install the module with:

$ cpan LaTeX::Table

Then for example, enter the following into a buffer:

theme=NYC;caption_top=1;caption=Bla
Animal & Description & Price
Gnat & per gram & 13.65
& each & 0.02
Gnu & stuffed & 92.59

Now visually select the lines (for example, ggVG), and enter the command !ltpretty to filter the text through the ltpretty script. The lines are replaced with the following LaTeX code:

 % theme=NYC;caption_top=1;caption=Bla
 % Animal & Description & Price
 % Gnat & per gram & 13.65
 % & each & 0.02
 % Gnu & stuffed & 92.59

\definecolor{latextbl}{RGB}{78,130,190}
\begin{table}
\centering
\caption{Bla}
\setlength{\extrarowheight}{1pt}
\begin{tabular}{|llr|}
\hline
\rowcolor{latextbl}\multicolumn{1}{|>{\columncolor{latextbl}}c}{\color{white}\textbf{Animal }} & \multicolumn{1}{>{\columncolor{latextbl}}c}{\color{white}\textbf{ Description }} & \multicolumn{1}{>{\columncolor{latextbl}}c|}{\color{white}\textbf{ Price}} \\
\hline
\rowcolor{latextbl!25}Gnat & per gram & 13.65 \\
\rowcolor{latextbl!10}     & each     & 0.02  \\
\rowcolor{latextbl!25}Gnu  & stuffed  & 92.59 \\
\hline
\end{tabular}
\end{table}

Comments[]

A similar alternative is the ViLaTaC script that can be downloaded from https://github.com/tannhuber/vilatac. It provides individual column formatting with a very simple syntax. However, it is intended for publishing. Thus, colorful themes are not supported.