On TeX.SE the Help Centre says that the following is on topic:

Formats like LaTeX, ConTeXt and plain TeX
Engines like pdfTeX, LuaTeX and XeTeX
Distributions like TeX Live, MiKTeX, and MacTeX
Related software and tools, BibTeX, MakeIndex, Lyx, etc.

I wanted you to write a program to tell me whether my TeX is in the on-topic types of TeX.

An explicit list of the valid TeX-s is as follows:

  • MetaPost
  • PostScript
  • MetaFUN
  • TeX
  • LaTeX
  • LuaLaTeX
  • LuaTeX
  • ConTeXt
  • BibTeX
  • pdfTeX
  • Lyx
  • MakeIndex
  • TeX Live
  • XeLaTeX
  • XeTeX
  • MacTeX
  • MiKTeX


  • You may use any language.
  • This is , to the shortest answer wins.
  • If you use Regex, you can just match correct ones.
  • You only need to match one at a time: no

    Lyx BibTeX

  • You must check with capitalization listed here.


TeX -> True/1/<match>
pTeX -> False/0/<not-match>
ConTeXt -> True/1/<match>
context -> False/0/<not-match>
MetaFun -> False/0/<not-match>
MetaFUN -> True/1/<match>

P.S. Bonus points for an on-topic TeX answer!

  • 6
    \$\begingroup\$ @closevoter This is a tips question, which is explicitly on-topic. \$\endgroup\$
    – DJMcMayhem
    Jul 3, 2016 at 20:41
  • 2
    \$\begingroup\$ You also seem to be missing MiKTeX in your full list. \$\endgroup\$ Jul 4, 2016 at 6:02
  • 1
    \$\begingroup\$ Why not make this a challenge? \$\endgroup\$
    – user45941
    Jul 4, 2016 at 7:17
  • 2
    \$\begingroup\$ @DrGreenEggsandIronMan, it's tagged tips, but it looks far too specific to be a tips question. I agree with Mego that it's really a challenge, but as a challenge it seems to be a moral duplicate of existing "write a regex to match everything in this list" questions. \$\endgroup\$ Jul 4, 2016 at 7:28
  • 3
    \$\begingroup\$ @DrGreenEggsandIronMan, surely if an existing question's answers answer a new question, that new question is a duplicate, regardless of the tags? The purpose of tags is to help people find similar questions, not to be magical talismen. \$\endgroup\$ Jul 4, 2016 at 8:43

4 Answers 4


JavaScript Regex, 99 101 99 97 + 1 for g flag = 98 bytes

^(((Xe|Lua)?(La)?|Bib|MiK|pdf|Mac)TeX|ConTeXt|TeX Live|Meta(FUN|Post)|PostScript|MakeIndex|Lyx)$

Test it here. Type into the Text box. Alternatively, test it here.

var j = $("#dos");
var text;
function abc(){
  text = $('#uno').val();
  j.val(text.match(/^(((Xe|Lua)?(La)?|Bib|MiK|pdf|Mac)TeX|ConTeXt|TeX Live|Meta(FUN|Post)|PostScript|MakeIndex|Lyx)$/g) == text ? "Matches!" : "No match!");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id='uno' /><br />
<button id='tres' onclick="javascript:abc()">Test!</button><br/>
<input id='dos' />

Test all cases:

var j = $("#dos");
var tests = ["TeX", "pTeX", "ConTeXt", "context", "MetaFun", "MetaFUN", "TeX Live"];
function abc(e){
  j.val(j.val() + e + ": " + (e.match(/^(((Xe|Lua)?(La)?|Bib|MiK|pdf|Mac)TeX|ConTeXt|TeX Live|Meta(FUN|Post)|PostScript|MakeIndex|Lyx)$/g) == e ? "Matches!" : "No match!") + "\n");

function def(){
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id='tres' onclick="javascript:def()">Test!</button><br/>
<textarea rows=50 cols=200 id='dos'>

  • 2
    \$\begingroup\$ As a code-golf challenge answer, this seems to be invalid as it is not a program or function. \$\endgroup\$
    – feersum
    Jul 5, 2016 at 4:59
  • \$\begingroup\$ @feersum Except my challenge allows regex. \$\endgroup\$ Jul 5, 2016 at 16:16
  • \$\begingroup\$ Is the ^ in the starting and $ at the end of the regular expression really necessary? \$\endgroup\$
    – R. Kap
    Jul 6, 2016 at 3:41
  • \$\begingroup\$ @R.Kap Yes. Otherwise pTeX will match. \$\endgroup\$ Jul 6, 2016 at 3:57
  • \$\begingroup\$ Ah, I nearly forgot the regex. \$\endgroup\$
    – user54200
    Jul 6, 2016 at 14:30

Perl 5, 103 bytes

102 bytes, plus 1 for -pe instead of e. Stdin→stdout.

$_=/^(Meta(Post|FUN)|TeX Live|PostScript|((Xe|Lua)?(La)?|Bib|pdf|M(ac|iK))TeX|ConTeXt|Lyx|MakeIndex)$/

Python 3.5, 149 147 137 136 bytes

import re;lambda f:re.fullmatch('TeX Live|(La|LuaLa|Lua|Bib|pdf|XeLa|Xe|Mac|MiK)?TeX|Lyx|MakeIndex|Meta(Post|FUN)|PostScript|ConTeXt',f)

An anonymous function that uses a regular expression to return a re match object (such as <_sre.SRE_Match object; span=(0, 5), match='LaTeX'>) as a truthy value and None as a falsy value. The actual regular expression is currently 102 100 99 bytes in length.

Try It Online! (Ideone)

  • \$\begingroup\$ Why if/else? It will still work without the if/else-s because return x == return (1 if x else 0) logically. \$\endgroup\$ Jul 6, 2016 at 14:35
  • \$\begingroup\$ @NoOneIsHere I was not sure if I had to, but I was making it so that it returns a truthy/falsy value based on whether a match was found or not. However, if you are fine with a re match object being returned, I'll change it. I just was not sure what kind of output you wanted, so I did this. \$\endgroup\$
    – R. Kap
    Jul 6, 2016 at 17:44
  • \$\begingroup\$ According to the Defaults for I/O, if bool(x) == True, then it is allowed. \$\endgroup\$ Jul 6, 2016 at 17:45
  • \$\begingroup\$ @NoOneIsHere So it's okay if something like <_sre.SRE_Match object; span=(0, 5), match='LaTeX'> is returned when a match is found? \$\endgroup\$
    – R. Kap
    Jul 6, 2016 at 17:46
  • \$\begingroup\$ Yes, as long as bool(x) is True. \$\endgroup\$ Jul 6, 2016 at 17:47

Thunno, \$ 122 \log_{256}(96) \approx 100.42 \$ bytes

"MetaPost|PostScript|MetaFUN|?|La?|LuaLa?|Lua?|ConTeXt|Bib?|pdf?|Lyx|MakeIndex|? Live|XeLa?|Xe?|Mac?|MiK?"'?"TeX"AR'|ZisAq

Attempt This Online!

"..."'?"TeX"AR'|ZisAq  # Implicit input
"..."                  # Push the string
            AR         # Replace...
     '?                # ...the character '?'...
       "TeX"           # ...with the string "TeX"
                Zi     # Split the resulting string...
              '|       # By the character '|'
                  sAq  # Is the input in this list?
                       # Implicit output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.