Wave2LaTeX
// Create a LaTeX table from waves
// Version 2
// Operates in current data folder and returns theTable as a string
// output is in column format, one wave per column
// waves can be numeric or string
// ==> waves: a semicolon list of wave names to tabulate
// ==> rowend: (optional) string to add to the end of each row
Function/S Wave2LaTeX(waves,[rowend])
string waves, rowend
// strings and variables
string theTable = "", theText = ""
variable ic, nt, maxl, jc, theValue
// default rowend parameter
if (ParamIsDefault(rowend))
rowend = ""
endif
// how many columns to create
nt = ItemsInList(waves)
// create free waves to translate inputs
make/T/n=(nt)/FREE theWaves
make/n=(nt)/FREE theLengths
// put wave names in to text wave storage
// put lengths of waves in to wave storage
for(ic=0;ic<nt;ic+=1)
theWaves[ic] = StringFromList(ic,waves)
theLengths[ic] = numpnts($theWaves[ic])
endfor
// how many rows do we need?
maxl = wavemax(theLengths)
// proccess each row
for(ic=0;ic<maxl;ic+=1)
theText = ""
// do up to the last column
for(jc=0;jc<nt-1;jc+=1)
switch(wavetype($theWaves[jc],1))
case 1: // numeric wave
wave theOne = $theWaves[jc]
if (numpnts(theOne)>maxl)
sprintf theText, "%s\t&", theText
else
sprintf theText, "%s%g\t&", theText, theOne[ic]
endif
break
case 2: // text wave
wave/T theTOne = $theWaves[jc]
if (numpnts(theTOne)>maxl)
sprintf theText, "%s\t&", theText
else
sprintf theText, "%s%s\t&", theText, theTOne[ic]
endif
break
endswitch
endfor
// add the last column
switch(wavetype($theWaves[nt],1))
case 1: // numeric wave
wave theOne = $theWaves[nt]
if (numpnts(theOne)>maxl)
sprintf theText, "%s \\\\ %s\r", theText, rowend
else
sprintf theText, "%s%g \\\\ %s\r", theText, theOne[ic], rowend
endif
break
case 2: // text wave
wave/T theTOne = $theWaves[nt]
if (numpnts(theTOne)>maxl)
sprintf theText, "%s \\\\ %s\r", theText, rowend
else
sprintf theText, "%s%s \\\\ %s\r", theText, theTOne[ic], rowend
endif
break
endswitch
theTable += theText
endfor
return theTable
end
Forum
Support
Gallery
Igor Pro 10
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
This is great, I modified to support replace NaN by " " and deal with text waves as well (see below). However, I ran into a problem with the macro using wavelist to find the waves in a given table. It seems that the list is not ordered according to the column order. How could I correct that to make this export to LaTex better ?
August 18, 2014 at 03:09 pm - Permalink
I do not include the \begin{...} ... \end{..} sections marks. They are for individuals to make on their own.
I do not change NaN or INF designations. The %g format gives them directly in a way that can be altered later via a blanket find/replace on the text editor.
As to the other question about the order of waves from tables to string lists ... I do not have an immediate answer other than that WaveList has to be properly configured in how it reads the table. This is not a problem to handle inside this code segment.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
August 19, 2014 at 01:59 pm - Permalink
Here is a slight tweak of Wave2LaTex!
This snippet takes a 2D wave with x and y dimension labels, i.e.
and then makes a table from it, including the text labels. The LaTex code is directly put to Clipboard from where it can be pasted in to a text editor. Not extensively tested!!
July 26, 2018 at 01:02 am - Permalink