Hello fellow maters,
A while ago we had a command that would align statements at their = signs…
Would it be possible to incorporate that feature into the table- macros fo LaTeX? So that the tables cells are aligned at the & signs? And possibly make a command out of this that would re-format existing tables?
just wondering if anyone feels like it ;)
Dan …in his final stages of actually beating that thesis writing monster…
On Jul 30, 2006, at 4:50 AM, Daniel Käsmayr wrote:
Hello fellow maters,
A while ago we had a command that would align statements at their = signs…
Would it be possible to incorporate that feature into the table- macros fo LaTeX? So that the tables cells are aligned at the & signs? And possibly make a command out of this that would re-format existing tables?
just wondering if anyone feels like it ;)
Here is a first take at it. It requires that you select the rows you want to work on. Let me know if it works consistently in this case. Input to selected text, output to replace selection.
#!/usr/bin/env ruby require 'pp' lines = STDIN.readlines.map {|line| line.chomp.split(/\s*&\s*/)} table_lines = lines.reject{|line| line.length == 1} columns = table_lines.shift.zip(*table_lines) columns_lengths = columns.map{|column| column.map{|i| i.length}.max} pattern = columns_lengths.map{|i| "%-#{i}s"}.join(" & ") + "\n" for line in lines do if line.length == 1 then puts line else printf(pattern,*line) end end
Dan …in his final stages of actually beating that thesis writing monster…
Good luck!!
Haris
Haris,
Thank you! it isn't perfect (yet) ;) the first table I tried it on was snafu,
becomes
but in other cases it is quite nice and fully functioning?!
Am 30. Jul 2006 um 18:21 schrieb Charilaos Skiadas:
Good luck!!
Thanks, I am having the "I quit" feeling every hour now or so – just pi**es me off ;) Tomorrow I will turn the monster in for some corrections and feedback… it will be interesting to see what others think of it ;)
Dan
On Jul 30, 2006, at 11:42 AM, Daniel Käsmayr wrote:
Haris,
Thank you! it isn't perfect (yet) ;) the first table I tried it on was snafu,
but in other cases it is quite nice and fully functioning?!
Ah, you use tabs ;) and the first column might not have much stuff in it ;) In fact that's the problem I think, my script will get rid of any continuous stretch of whitespaces before the &. I'll play with your example when I get a chance and hopefully have something soon. Though right now, I got to move to a new state.
Am 30. Jul 2006 um 18:21 schrieb Charilaos Skiadas:
Good luck!!
Thanks, I am having the "I quit" feeling every hour now or so – just pi**es me off ;)
Yeah, i had that feeling for quite a while. The only thing that kept me going is thinking of all the doors this would open for me, and all the years that are invested in it.
Tomorrow I will turn the monster in for some corrections and feedback… it will be interesting to see what others think of it ;)
Make sure you have some friend proofread it for you, someone who you can trust would go through it thoroughly.
Dan
Haris
On Jul 30, 2006, at 1:05 PM, Daniel Käsmayr wrote:
Am 30. Jul 2006 um 19:02 schrieb Charilaos Skiadas:
Ah, you use tabs ;) and the first column might not have much stuff in it ;)
Also it seems that Special characters like µ or ä change things?
Ah yes, this might be harder to solve. I use Ruby's String#length method, which doesn't count unicode characters properly in its current implementation. That would require a bit more thinking.
Dan
Haris
On 30/7/2006, at 20:18, Charilaos Skiadas wrote:
Also it seems that Special characters like µ or ä change things?
Ah yes, this might be harder to solve. I use Ruby's String#length method, which doesn't count unicode characters properly in its current implementation. That would require a bit more thinking.
% ruby -rjcode -KU -e 'puts "µä".jlength' 2
However, as you use %«n»s for padding, and that one is not mb-aware, another approach would be needed for padding the columns.
It seems to me a bit odd that Unicode characters are not universally supported ruby most of the time - I would have expected nothing less from ruby, at least ;)
Ah well, fun to live in weird-keyboard-old-world-europe,
Dan
According to Daniel Käsmayr:
It seems to me a bit odd that Unicode characters are not universally supported ruby most of the time - I would have expected nothing less from ruby, at least ;)
This is one of the main gripes people have with Ruby, it is difficult to admit that a language written by a Japanese guy not to be i18n/m17n aware.
I even heard people saying they'd stick with python for that reason.
Matz has some good reasons but it is still difficult :(
IIRC full unicode support is planned for 2.0, or something along those lines.
Ah yes, _why talks about it: http://redhanded.hobix.com/inspect/futurismUnicodeInRuby.html
He also mentions a third-party library for UTF-8 support that works in 1.8: http://redhanded.hobix.com/inspect/nikolaiSUtf8LibIsAllReady.html
On Mon, 31 Jul 2006, Ollivier Robert wrote:
According to Daniel K�smayr:
It seems to me a bit odd that Unicode characters are not universally supported ruby most of the time - I would have expected nothing less from ruby, at least ;)
This is one of the main gripes people have with Ruby, it is difficult to admit that a language written by a Japanese guy not to be i18n/m17n aware.
I even heard people saying they'd stick with python for that reason.
Matz has some good reasons but it is still difficult :(
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
There is another Problem if a table row contains a &: the command thinks this is a & for alignment, but in the end it deletes the overhanging table cell!
Dan
On Jul 30, 2006, at 4:21 PM, Daniel Käsmayr wrote:
There is another Problem if a table row contains a &: the command thinks this is a & for alignment, but in the end it deletes the overhanging table cell!
Yes, I kind of expected that to happen actually. I went for the quickest and dirtiest method I could come up with, mostly to show that you can do it with a very short script. For a quick fix, define a command, say \amp, that generates &, and use that instead.
As for unicode support, it is a bit complicated, and there is a quite long thread in ruby-talk you can follow if you are interested. It's not that you can't use unicode characters in strings, you can. Also, regular expressions will work just fine. But a couple of commands like “length” and “downcase” and others won't do the “right thing”.
Dan
Haris