psql latex and newlines

Started by Wim Bertelsover 14 years ago8 messagesgeneral
Jump to latest
#1Wim Bertels
wim.bertels@khleuven.be

Hallo,

psql latex output format needs to differentiate between a newline and a
tabularnewline.

the problem arises when u have a field value that contains a newline
character, when this field is not the first column, then all the data
after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on this function or
table.

the \pset recordsep doesn't solve this, since the mistakes take place
within the same record.

so first:
make some function of table
\o tofile
\pset format latex
\df+ \dt+ or ..

eg:
-- latex generated: with the wrong layout

\begin{tabular}{|c|l|}

\hline

\multicolumn{2}{|c|}{\textit{Record 1}} \\

\hline

entry1\_test & test \\

..

out\_result & TABLE(out\_field1 integer,\\ out\_field2 character
varying,\\ out\_del boolean) \\
out\_description & This function deletes a record\\ given the
following .. foreign\_key\_violation.\\ \\

\hline

Compared with text output, right layout:
-[ RECORD1 ]------------+--------------------------------------------------------------
entry1_test | test
..

out_resultdatatypes | TABLE(out_field1 integer,
: out_field2 character varying,
: out_del boolean)
out_description | This function deletes a record
: given the following ..
..
: .. foreign_key_violation.

mvg,
Wim

#2Bruce Momjian
bruce@momjian.us
In reply to: Wim Bertels (#1)
Re: psql latex and newlines

On Mon, Dec 12, 2011 at 07:15:12PM +0100, Wim Bertels wrote:

Hallo,

psql latex output format needs to differentiate between a newline and a
tabularnewline.

the problem arises when u have a field value that contains a newline
character, when this field is not the first column, then all the data
after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on this function or
table.

the \pset recordsep doesn't solve this, since the mistakes take place
within the same record.

Can you give me a self-contained test case I can use so I can use it to
fix the to code?

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#3Wim Bertels
wim.bertels@khleuven.be
In reply to: Bruce Momjian (#2)
Re: psql latex and newlines

On vr, 2012-02-10 at 19:25 -0500, Bruce Momjian wrote:

On Mon, Dec 12, 2011 at 07:15:12PM +0100, Wim Bertels wrote:

Hallo,

psql latex output format needs to differentiate between a newline and a
tabularnewline.

the problem arises when u have a field value that contains a newline
character, when this field is not the first column, then all the data
after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on this function or
table.

the \pset recordsep doesn't solve this, since the mistakes take place
within the same record.

Can you give me a self-contained test case I can use so I can use it to
fix the to code?

Hi Bruce,

i have attached some files:
1 sql file
1 corresponding output file
1 full latex file using the output of the above file

i don't see and easy search/replace fix for this problem,
maybe using the \multirow and \multicolumn options in latex is the most
general solution,
as all the others seems to need concrete dimensions (as width)

http://www.google.com/search?client=ubuntu&amp;channel=fs&amp;q=newline+tabular
+cell+latex&ie=utf-8&oe=utf-8

http://andrewjpage.com/index.php?/archives/43-Multirow-and-multicolumn-spanning-with-latex-tables.html

There is also a problem with long lines as u can test by uncommenting
the t4bruce3 function.

info about the versions:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 10.04.3 LTS
Release: 10.04
Codename: lucid
wim@zwerfkat:~/wet/gb/postgresql/debug$ psql -V
psql (PostgreSQL) 8.4.10
contains support for command-line editing

mvg,
Wim Bertels

Show quoted text

Attachments:

working_out.textext/x-tex; charset=UTF-8; name=working_out.texDownload
out.textext/x-tex; charset=UTF-8; name=out.texDownload
latex_newline_problem.sqltext/x-sql; charset=UTF-8; name=latex_newline_problem.sqlDownload
#4Bruce Momjian
bruce@momjian.us
In reply to: Wim Bertels (#3)
Re: psql latex and newlines

On Mon, Feb 13, 2012 at 02:50:12PM +0100, Wim Bertels wrote:

On vr, 2012-02-10 at 19:25 -0500, Bruce Momjian wrote:

On Mon, Dec 12, 2011 at 07:15:12PM +0100, Wim Bertels wrote:

Hallo,

psql latex output format needs to differentiate between a newline and a
tabularnewline.

the problem arises when u have a field value that contains a newline
character, when this field is not the first column, then all the data
after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on this function or
table.

the \pset recordsep doesn't solve this, since the mistakes take place
within the same record.

Can you give me a self-contained test case I can use so I can use it to
fix the to code?

Hi Bruce,

i have attached some files:
1 sql file
1 corresponding output file
1 full latex file using the output of the above file

i don't see and easy search/replace fix for this problem,
maybe using the \multirow and \multicolumn options in latex is the most
general solution,
as all the others seems to need concrete dimensions (as width)

http://www.google.com/search?client=ubuntu&amp;channel=fs&amp;q=newline+tabular
+cell+latex&ie=utf-8&oe=utf-8

http://andrewjpage.com/index.php?/archives/43-Multirow-and-multicolumn-spanning-with-latex-tables.html

There is also a problem with long lines as u can test by uncommenting
the t4bruce3 function.

Well, I was hoping you could tell me exactly how you wanted the behavior
changed and I could try to implement it in psql. I am afraid I don't
know enough about TeX to understand the isssue involved.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#5Wim Bertels
wim.bertels@khleuven.be
In reply to: Bruce Momjian (#4)
Re: psql latex and newlines

the problem arises when u have a field value that contains a newline
character, when this field is not the first column, then all the data
after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on this function or
table.

There is also a problem with long lines as u can test by uncommenting
the t4bruce3 function.

Well, I was hoping you could tell me exactly how you wanted the behavior
changed and I could try to implement it in psql. I am afraid I don't
know enough about TeX to understand the isssue involved.

Hi Bruce,

the option i came across is the usage of \pbox,
so the suggestion would be to put every field/cell inside a pbox.

Instead of
\begin{tabular}{l | l | l}
\textit{Schema} & \textit{Name} & \textit{Description} \\
\hline
latex\_test & t4bruce1 & This function and so on enter\\ another enter,\
\ just one more.\\ \\
latex\_test & t4bruce2 & This function and so on enter\\ another enter,\
\ just one more,\\ so now have even one more.\\ \\
\end{tabular}

the generated code could like:
\begin{tabular}{l | l | l}
\textit{Schema} & \textit{Name} & \textit{Description} \\
\hline
\pbox{\textwidth}{latex\_test} & \pbox{\textwidth}{t4bruce1} &
\pbox{\textwidth}{This function and so on enter\\ another enter,\\ just
one more.\\} \\
\pbox{\textwidth}{latex\_test} & \pbox{\textwidth}{t4bruce2} &
\pbox{\textwidth}{This function and so on enter\\ another enter,\\ just
one more,\\ so now have even one more.\\} \\
\end{tabular}

Comments:
- the improvement is that now newlines inside boxes stay inside these
boxes (or cells/fields), it is not a complete solution as very long
lines are not automatically formatted into several lines inside a box,
but if necessary the db-user can do a a search and replace in the
generated tex code s\textwidth\20cm for example, makes every box 20cm at
maximum. (maybe to be put in the docu somewhere as a comment on
textwidth). This all depends on the page format, unfortunately (for now?
in latex) the nice (p)aragraph formatting doesn't fully extend inside a
table (cf tabular)
- i'm not a tex specialist, but also the people i know didn't find a
better solution

mvg,
Wim

#6Harvey, Allan AC
HarveyA@OneSteel.com
In reply to: Wim Bertels (#5)
Re: psql latex and newlines

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Wim Bertels
Sent: Friday, 24 February 2012 2:46 AM
To: Bruce Momjian
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] psql latex and newlines

the problem arises when u have a field value that

contains a newline

character, when this field is not the first column,

then all the data

after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on

this function or

table.

There is also a problem with long lines as u can test by

uncommenting

the t4bruce3 function.

Well, I was hoping you could tell me exactly how you wanted

the behavior

changed and I could try to implement it in psql. I am

afraid I don't

know enough about TeX to understand the isssue involved.

Hi Bruce,

the option i came across is the usage of \pbox,
so the suggestion would be to put every field/cell inside a pbox.

Instead of
\begin{tabular}{l | l | l}
\textit{Schema} & \textit{Name} & \textit{Description} \\
\hline
latex\_test & t4bruce1 & This function and so on enter\\
another enter,\
\ just one more.\\ \\
latex\_test & t4bruce2 & This function and so on enter\\
another enter,\
\ just one more,\\ so now have even one more.\\ \\
\end{tabular}

the generated code could like:
\begin{tabular}{l | l | l}
\textit{Schema} & \textit{Name} & \textit{Description} \\
\hline
\pbox{\textwidth}{latex\_test} & \pbox{\textwidth}{t4bruce1} &
\pbox{\textwidth}{This function and so on enter\\ another
enter,\\ just
one more.\\} \\
\pbox{\textwidth}{latex\_test} & \pbox{\textwidth}{t4bruce2} &
\pbox{\textwidth}{This function and so on enter\\ another
enter,\\ just
one more,\\ so now have even one more.\\} \\
\end{tabular}

Comments:
- the improvement is that now newlines inside boxes stay inside these
boxes (or cells/fields), it is not a complete solution as very long
lines are not automatically formatted into several lines inside a box,
but if necessary the db-user can do a a search and replace in the
generated tex code s\textwidth\20cm for example, makes every
box 20cm at
maximum. (maybe to be put in the docu somewhere as a comment on
textwidth). This all depends on the page format,
unfortunately (for now?
in latex) the nice (p)aragraph formatting doesn't fully
extend inside a
table (cf tabular)
- i'm not a tex specialist, but also the people i know didn't find a
better solution

mvg,
Wim

My 2 cents worth is I would like to see the booktabs and longtable environments used to handle pages covering multiple pages. I have attached a zip containg a pdf of the different versions, the LaTex source.
The example is recast and extracted here:

Allan

\begin{longtable}{p{0.3\textwidth}p{0.3\textwidth}p{0.3\textwidth}}
\toprule
\centering{\small\textbf{\textit{Schema}}} & \small\textbf{\textit{Name}} & \small\textbf{\textit{Description}} \\
\midrule \\
\endfirsthead
\toprule
\centering{\small\textbf{\textit{Schema}}} & \small\textbf{\textit{Name}} & \small\textbf{\textit{Description}} \\
\midrule \\
\endhead

\bottomrule \\
\caption[List of Tables Entry. (Continued)]{Bottom Caption.}
\endfoot

\bottomrule \\
\caption[List of Tables Entry.]{Bottom Caption.}
\endlastfoot

% Table Entries
\raggedright{latex\_test}
&
\raggedright{t4bruce1}
&
\raggedright{This function and so on enter \\ another enter,\\ just one more.} \tabularnewline \\

\raggedright{latex\_test}
&
\raggedright{t4bruce1}
&
\raggedright{This function and so on enter \\ another enter,\\ just one more,\\ so now have even one more.} \tabularnewline \\

\end{longtable}

The material contained in this email may be confidential, privileged or copyrighted. If you are not the intended recipient, use, disclosure or copying of this information is prohibited. If you have received this document in error, please advise the sender and delete the document. Neither OneSteel nor the sender accept responsibility for any viruses contained in this email or any attachments.

Attachments:

psqlTeXtables.zipapplication/x-zip-compressed; name=psqlTeXtables.zipDownload
#7Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Wim Bertels (#5)
Re: psql latex and newlines

Excerpts from Wim Bertels's message of jue feb 23 12:46:29 -0300 2012:

the problem arises when u have a field value that contains a newline
character, when this field is not the first column, then all the data
after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on this function or
table.

the option i came across is the usage of \pbox,
so the suggestion would be to put every field/cell inside a pbox.

Did you come up with a patch for this?

--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#8Bruce Momjian
bruce@momjian.us
In reply to: Wim Bertels (#1)
Re: psql latex and newlines

On Tue, Apr 10, 2012 at 03:18:27PM +0200, Wim Bertels wrote:

On vr, 2012-03-30 at 16:25 +0200, Wim Bertels wrote:

On do, 2012-03-15 at 16:34 -0300, Alvaro Herrera wrote:

Excerpts from Wim Bertels's message of jue feb 23 12:46:29 -0300 2012:

the problem arises when u have a field value that contains a newline
character, when this field is not the first column, then all the data
after this newline comes in the first column..

u can try this out, writing a function or table,
and then add 'enters' or newline in the COMMENT on this function or
table.

the option i came across is the usage of \pbox,
so the suggestion would be to put every field/cell inside a pbox.

Did you come up with a patch for this?

A more polished version on page 7 and 8 of the pdf,
in attachment:
1. include the psql latex a separate file
2. use longtable instead of table
3. if horizontal lines are needed they can easily be uncommented

Looks good. Can I see the psql patch for this improvement?

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +