On 26 April 2012 02:33, Carnë Draug <carandraug+...@gmail.com> wrote: > On 25 April 2012 19:03, Markus Bergholz <marku...@gmail.com> wrote: >> 2012/4/24 Carnë Draug <carandraug+...@gmail.com>: >>> On 19 April 2012 10:24, Markus Bergholz <marku...@gmail.com> wrote: >>>> 2012/4/18 Markus Bergholz <marku...@gmail.com>: >>>>>> I believe this function would fit better in the miscellaneous package >>>>>> (and can you take a look at csv2latex and maybe publish on that >>>>>> package?). >>>>> >>>>> Oh, i didn't know that those package exist. >>>>> As far as i see it is similar as mine, only by going through a CSV >>>>> file, but with optionaly horizontal/vertical lines and optionaly >>>>> row/column titles. >>>>> >>>>> >>>>>> Also, you don't have a copyright notice on that function so we can't >>>>>> add it to Octave-Forge until then. I'd suggest GPLv3+ (that's the >>>>>> license octave itself and most code in octave-forge uses). >>>>> >>>>> I don't care about the licence. So GPLv3+ is fine too. >>>>> >>>>>> Quite a few different versions of this function have already been >>>>>> proposed, >>>>>> see for example this thread: >>>>>> >>>>>> http://octave.1599824.n4.nabble.com/Creating-Pretty-Report-from-Octave-tp2245980p2245980.html >>>>>> >>>>>> Maybe you could help by merging the features of all variants into one? >>>>> >>>>> I'll take a look and see what my lousy octave skills can do :) >>>>> >>>>> >>>>> greetings >>>>> markus >>>> >>>> First i've change the name from matrix2textable to texwrite. >>>> Than I've include the features of the csv2tex (switching rows lines >>>> on/off, column on/off, alignment set to left/right/center). But i've >>>> don't include the rows/column titles/naming. I don't know if it is >>>> needed and don't know how to handle it. >>>> Then i've added a display in matrix feature. >>>> I've added the code and an example pdf, how does it all look like, but >>>> i don't know how smooth the code is. >>>> >>>> greetings >>>> markus >>> >>> Hi Markus >>> >>> sorry for the very late reply. >> >> it's okey :) >> >>> I have rewrote the documentation of the >>> function so as to use texinfo properly. I have also renamed textable. >>> I have made a few changes, specially with the input handling, how the >>> defaults are set up and a very minimum input checking and then >>> comitted it. Please see >>> http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/miscellaneous/inst/textable.m >>> >>> Note how the defaults are set up at the top with the line: >>> >>> function textable (data, filename, rlines = 1, clines = 1, alignment = >>> "r", matrixformat = 0) >>> endfunction >> >> i guess now it isn't working anymore (correctly). >> further more, textable output comes with a warning. >> >> warning: implicit conversion from matrix to sq_string > > I see what's wrong. You were checking if the argument exist to set > defaults. I had left one of those behind (the ones who sets everything > down to zero). Because alignment now had a value of zero, the warning > came from fprinf trying to convert it into string. I have fixed this > on. Can you confirm? > >>> I also didn't quite understand the sprintf('r') lines, there's no need >>> for that, you can assign the character directly to variable. >> >> if i tried that i get an error >> >> error: `r' undefined near line 4 column 27 > > If you are passing a string, you need to place quotes around it (in > octave we prefer double quotes). So it would be function_name("r") to > pass the character r. Without quotes, you'd whatever is in the > variable r which may not exist. > >>> And why not having the user entering the actual character rather than >>> a number? >>> It will make it easier to remember the API and what value >>> means. >> >> I don't know how to handle it. everything i've tried like that, ended >> in an error of undefined :) > > I'd propose the following API if you agree: > > 1) only argument needed actually needed would be a matrix. All other > would be optional > > 2) if an output is requested, then the table would be returned as a > string rather than saved in a file (this makes it easier for other > functions that generate latex code to use your as building block). For > example, the following would return the text into the variable table > and not create a tex file: > > table = textable (data); > > 3) All optional parameters can be defined by pairs of parameters and > values or switches. You can make this easily with inputParser class in > the general package and implement something like the following: > > textable (data, "filename", "table.tex", "alignment", "c") > textable (data, "alignment", "c", "filename", "table.tex") > table = textable (data, "clines", "rlines", "alignment", "c") > > Here, filename and alignment are two keys, and need to be followed by > their values. The default would be to have no vertical or horizontal > lines. If the values "rlines" or "clines" are also given, they work as > a switch, turning them on. These can be in any order, only the data > needs to be the first the argument. This could be implemented with > something like this (untested): > > function out = textable (data, varargin) > if (nargin < 1) > prrint_usage; > endif > p = inputParser; > p = p.addRequired ("data", @(x) ismatrix(x) && isnumeric(x)); > p = p.addSwitch ("clines") > p = p.addSwitch ("rlines") > p = p.addParamValue ("filename", "default.tex", @ischar) > p = p.addParamValue ("alignment", "r", @(x) any(strcmpi(x, {"l", "c", "r"}))) > p = p.parse (data, varargin{:}) > ## from now on, you can access the options with: > p.Results.filename > p.Results.alignment > if (p.Results.clines) > ## do as if clines == 1 from before > else > ## do as if clines == 0 from before > endif > > ##create table in string > > if (nargout > 0) > return string > else > print strint into file > endif > endfunction
Hi Marcus I made a lot of changes to the code you submitted and included the new API I mentioned. It should be more obvious for someone reading the code what it does. I have also added some more input checking to prevent problems. here's the commit message: textable: big rewriting of the function. It's dependent on inputParser from general (>= 1.3.1 as previous versions had a bug) * completely new API * can optionally get source on a string for further merging with others * removed \topline so as to not be dependent on booktabs package * can use lines even on array environment * source generated is aligned properly * input check (inclusive for matrix number of dimensions) * check if there was a error opening the file for writing Carnë ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev