SyntaxQ
Details
- If SyntaxQ returns False, you can find the position of a syntax error using SyntaxLength.
- form can be InputForm, StandardForm, TeXForm, TraditionalForm, or MathMLForm.
Examples
open all close allBasic Examples (2)
Test if a string is valid Wolfram Language syntax:
SyntaxQ["a[b[c,1],2],3]"]SyntaxQ["a[b[c,1],2]"]When SyntaxQ gives True, the string can be converted to an expression:
ToExpression["a[b[c,1],2]"]Request input from a dialog repeatedly until it is syntactically correct:
While[!SyntaxQ[input = InputString["Please enter a Mathematica expression"]], Print[input, " is not valid Mathematica syntax."]];ToExpression[input]Scope (2)
Verify a TeXForm input:
SyntaxQ["x+\\frac{1}{2}", TeXForm]This can be converted to a Wolfram Language expression:
ToExpression["x+\\frac{1}{2}", TeXForm]SyntaxQ can verify strings containing StandardForm or TraditionalForm boxes:
SyntaxQ[ToString[x^2 + y^2, StandardForm]]It does not accept the boxes themselves:
SyntaxQ[ToBoxes[x^2 + y^2, StandardForm]]Properties & Relations (2)
The default interpretation form is InputForm:
SyntaxQ["<math><mfrac><mi>π</mi><mn>4</mn></mfrac></math>"]SyntaxQ["<math><mfrac><mi>π</mi><mn>4</mn></mfrac></math>", InputForm]This input is valid MathMLForm:
SyntaxQ["<math><mfrac><mi>π</mi><mn>4</mn></mfrac></math>", MathMLForm]Use SyntaxLength to find the longest leading substring which is syntactically valid:
SyntaxQ["Sin]x["]SyntaxLength["Sin]x["]See Also
ToExpression SyntaxLength $SyntaxHandler WolframLanguageData DelimiterFlashTime
Function Repository: ValidSymbolIdentifierQ
Tech Notes
Related Guides
History
Introduced in 1991 (2.0) | Updated in 2017 (11.1)
Text
Wolfram Research (1991), SyntaxQ, Wolfram Language function, https://reference.wolfram.com/language/ref/SyntaxQ.html (updated 2017).
CMS
Wolfram Language. 1991. "SyntaxQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/SyntaxQ.html.
APA
Wolfram Language. (1991). SyntaxQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SyntaxQ.html
BibTeX
@misc{reference.wolfram_2026_syntaxq, author="Wolfram Research", title="{SyntaxQ}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/SyntaxQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_syntaxq, organization={Wolfram Research}, title={SyntaxQ}, year={2017}, url={https://reference.wolfram.com/language/ref/SyntaxQ.html}, note=[Accessed: 13-June-2026]}