Question: Consider the following sample:

```
π
SelectionMove[EvaluationNotebook[], Previous, CellContents, 1]; 
FrontEndExecute[FrontEndToken[EvaluationNotebook[], "CopySpecial", 
                              (* Place "MathML" or "CopyAsTeX" here *)]]

```

It is supposed to copy `π` as LaTeX or MathML but doesn't work. Just execute it, you'll see message box popping up. 

I guess it may be because *this token has not been fully integrated into the long-term Wolfram Language, and is subject to change* so the parameter representing MathML and LaTeX has been changed while the document isn't updated, but what's the correct token now?

…OK, the above question may be too hard, then are there any other alternatives for copying code as LaTeX or MathML programmatically?

I'm on v9.0.1, Win10 64bit.

Answer: 
Here's the reply from WRI:

> 
> The only Front-End tokens which are supported are those used by menu
>  items. They are not guaranteed to remain the same from version to
>  version. 
> 
> 
> The MenuSetup.tr file for your Mathematica and language is under  
> 
>  (installation directory)/SystemFiles/FrontEnd/TextResources/ 
>  Interpreting it is not always easy, but it shows the tokens and
>  functions available. 
> 
> 
> The attached notebook has working examples in Mathematica 10.3.1. *(I'll post the solution at the end of this answer.)*
> 
> 
> There are already suggestions for the documentation on Front End 
>  tokens to be updated.
> 
> 
> 

Now at least from v8.0.4, one can use the undocument functions `FrontEnd`CopyAsMathML[]` / `FrontEnd`CopyAsTeX[]` to copy as MathML / LaTeX programmatically. Here is an example that copies `π` as LaTeX:

```
(* The following code should be placed in one cell *)
π 
SelectionMove[EvaluationNotebook[], Previous, CellContents, 1]; 
FrontEnd`CopyAsTeX[];

```
Assuming there's a 2D expression in the first cell of your current notebook,

[![enter image description here](https://i.stack.imgur.com/BfbgB.png)](https://i.stack.imgur.com/BfbgB.png)

the following code shall copy the "MathML" to clipboard.

```
nb = NotebookRead@First@Cells[];
CopyToClipboard@ExportString[
    nb, "MathML"]

(*
    <math xmlns='http://www.w3.org/1998/Math/MathML'>
     <mfrac>
       <mn>1</mn>
       <msqrt>
       <mrow>
       <msup>
       <mi>x</mi>
       <mn>2</mn>
       </msup>
       <mo>+</mo>
     <mn>1</mn>
    </mrow>
   </msqrt>
  </mfrac>
 </math>
*)

```

Note that `nb` can be any cell expression, which can be obtained by `NotebookRead` from `NotebookSelection`, `Cells`, etc.

Concerning the $\LaTeX$ form, replacing `"MathML"` with `"TeXFragment"` produces slightly different result from the context menu's. Totally $\LaTeX$ illiterate, so I don't know what it means.