Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Extract terms from a sum

Is there some way to programmatically extract the first, second, third, and so on terms from a sum of symbolic terms (or equivalently, turn such a sum into the list of its summands)? For example, after

sage: A,B,C = var('A'), var('B'), var('C') 
sage: F = A*B+C; F
A*B + C

Is there some method you can call on F to extract A*B (or C)? This would be useful especially for displaying sage in LaTeX via sageTeX when a formula that is the sum of 4 terms (say) runs over the margin and has to be split up somehow. I would also be interested in a workaround in sageTeX that would allow you to flexibly insert a linebreak in a formula under the circumstances that the formula generated by Sage got too long for a line.