TeX - LaTeX Asked by Faheem Mitha on November 21, 2020
I’m trying to find a way to extract coordinates from an ordered pair in TeX. See this example code.
documentclass[12pt]{article}
usepackage{xparse}
begin{document}
% #1 and #2 are ordered pairs
NewDocumentCommand{coord}{ m m }
{
#1, #2
% Ordered pairs which correspond to (a) first coordinate of first pair and second
% coordinate of second pair, (b) second coordinate of first pair and first coordinate of
% second pair.
(#1[1], #2[2]), (#1[2]. #2[1])
}
coord{(1, 2)}{(3, 4)}
end{document}
The expected output from coord{(1, 2)}{(3, 4)}
would be
(1, 2), (3, 4)
(1, 4), (2, 3)
Because your desired syntax uses {...}{...}
, we need to remove them first and then to read the coordinates again by coordA macro.
defcoord#1#2{coordA#1#2}
defcoordA(#1,#2#3)(#4,#5#6){par(#1, #2#3), (#4, #5#6)par(#1, #5#6), (#4, #2#3)par}
coord{(1, 2)}{(3, 4)}
The trick #2#3)
instead only #2)
removes the optional space before such parameter.
Correct answer by wipet on November 21, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP