Wave2LaTeX

Average rating
(0 votes)

This string function returns values from numeric waves into a simple LaTeX table format.

// Create a LaTeX table from waves
// Operates in current data folder and returns theTable as a 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
 
	string theTable = "", theText = ""	
	variable ic, nt, maxl, jc, theValue
 
	if (ParamIsDefault(rowend))
		rowend = ""
	endif
 
	nt = ItemsInList(waves)
 
	make/T/n=(nt)/FREE theWaves
	make/n=(nt)/FREE theLengths
 
	for(ic=0;ic<nt;ic+=1)
		theWaves[ic] = StringFromList(ic,waves)
		theLengths[ic] = numpnts($theWaves[ic])
	endfor
 
	maxl = wavemax(theLengths)
 
	for(ic=0;ic<maxl;ic+=1)
		theText = ""
		for(jc=0;jc<nt-1;jc+=1)
			wave theOne = $theWaves[jc]
			if (numpnts(theOne)>maxl)
				sprintf theText, "%s\t&", theText
			else
				sprintf theText, "%s%g\t&", theText, theOne[ic]
			endif
		endfor
		wave theOne =  $theWaves[jc]
		if (numpnts(theOne)>maxl)
			sprintf theText, "%s \\\\ %s\r", theText, rowend
		else
			sprintf theText, "%s%g \\\\ %s\r", theText, theOne[ic], rowend
		endif
		theTable += theText
	endfor
 
	return theTable
end

Back to top