I'm writing a class for a document that formats a lot of simple paragraphs as tables. I know, that all tables follow a fixed number of columns, but have a variable number of rows. What I would like to do is writing a macro, that if issued once creates a single-row table and if issued n-times creates an n-row table. I'm interested in a general solution, that allows to insert any piece of code before the first instance of a macro and after the last but not in-between repeated calls to the same macro. Below is a minimal example of what output I want to achieve:
\documentclass[a4paper]{scrarticle}
\usepackage{tabularx}
\begin{document}
One row example:
\begin{tabular}{|c|c|}
\hline
Some & Text\
\hline
\end{tabular}
Two row example:
\begin{tabular}{|c|c|}
\hline
Some & Text\
\hline
Other & Line\
\hline
\end{tabular}
\end{document}
I want to have a command that allows me to just write the table rows and everything else is added automatically. So with a hypothetic command autotable the above example would look like:
[...]
\begin{document}
One row example:
\autotable{Some}{Text}
Two row example:
\autotable{Some}{Text}
\autotable{Other}{Line}
\end{document}
A concise answer explaining why that is not possible (if so) would also be quite helpful as I could achieve something like this using python/jinja instead if needed. Not completely unrelated questions: Look-ahead on token stream?, Macro: Expand differently depending on pattern?
Edit
This is the code taken from the accepted solution by David with added \hlines so the output created matches the exact output from the initial minimal example:
\documentclass[a4paper]{scrarticle}
\makeatletter
\def\autotable{\par\begin{tabular}{|c|c|}
\hline
\autotable@row}
\def\autotable@row#1#2{%
#1
@ifnextchar\autotable\autotable@gobble{\\hline\end{tabular}\par}}
\def\autotable@gobble#1{\\hline\autotable@row}
\makeatother
\begin{document}
One row example:
\autotable{Some}{Text}
Two row example:
\autotable{Some}{Text}
\autotable{Other}{Line}
\end{document}

\hlineworking as well? – Dschoni May 03 '21 at 09:35not in-between repeated calls to the same macro.said nothing would be placed? :-) If you always want\hlinejust add it after the\\in autotable@gobbe, if only sometimes then it depends on the syntax perhaps easiest to make it an optional argument so\autotable[\hline]{this}{that}although an option which only allows \hline is a bit odd – David Carlisle May 03 '21 at 10:31\autotable{\hline this}{that}works and call it a feature. – David Carlisle May 03 '21 at 10:54@syntax? I seem to be to dumb to google that... – Dschoni May 10 '21 at 07:28@is simply being used as a letter here. See https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do – David Carlisle May 10 '21 at 07:30