nebius/SWE-bench-extra huggingface dataset:
Repository: alvinwan/TexSoup

Issue:
\def\command not parsed correctly
For example, `\def\arraystretch{1.1}` will be parsed as `\def{\}{arraystretch}{1.1}`. The bad part of this result is it breaks the balance of braces as `\}` is escaped. 

Comments:

Patch:
diff --git a/TexSoup/data.py b/TexSoup/data.py
index f7279c8..58cd070 100644
--- a/TexSoup/data.py
+++ b/TexSoup/data.py
@@ -1317,7 +1317,7 @@ class TexArgs(list):
         """
         arg = self.__coerce(arg)
 
-        if isinstance(arg, TexGroup):
+        if isinstance(arg, (TexGroup, TexCmd)):
             super().insert(i, arg)
 
         if len(self) <= 1:
diff --git a/TexSoup/reader.py b/TexSoup/reader.py
index 3347393..fd53989 100644
--- a/TexSoup/reader.py
+++ b/TexSoup/reader.py
@@ -391,7 +391,7 @@ def read_arg_required(
        b. A curly-brace delimiter. If the required argument is brace-delimited,
           the contents of the brace group are used as the argument.
        c. Spacer or not, if a brace group is not found, simply use the next
-          character.
+          character, unless it is a backslash, in which case use the full command name
 
     :param Buffer src: a buffer of tokens
     :param TexArgs args: existing arguments to extend
@@ -422,7 +422,12 @@ def read_arg_required(
             n_required -= 1
             continue
         elif src.hasNext() and n_required > 0:
-            args.append('{%s}' % next(src))
+            next_token = next(src)
+            if next_token.category == TC.Escape:
+                name, _ = read_command(src, 0, 0, tolerance=tolerance, mode=mode)
+                args.append(TexCmd(name, position=next_token.position))
+            else:
+                args.append('{%s}' % next_token)
             n_required -= 1
             continue
 


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 136710e..bb175ff 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -384,6 +384,14 @@ def test_def_item():
     assert soup.item is not None
 
 
+def test_def_without_braces():
+    """Tests that def without braces around the new command parses correctly"""
+    soup = TexSoup(r"\def\acommandname{replacement text}")
+    assert len(soup.find("def").args) == 2
+    assert str(soup.find("def").args[0]) == r"\acommandname"
+    assert str(soup.find("def").args[1]) == "{replacement text}"
+
+
 def test_grouping_optional_argument():
     """Tests that grouping occurs correctly"""
     soup = TexSoup(r"\begin{Theorem}[The argopt contains {$]\int_\infty$} the square bracket]\end{Theorem}")