1
$\begingroup$

I have a palette that formats input cells for display, and also copies the number of cells in DisplayFormulaNumbered format so I can paste references to them in the text of the notebook I am creating. The code is

stylebuttons = (Button[Style[#1, 14, FontFamily -> "Calibri"], 
  FrontEndTokenExecute[InputNotebook[], "Style", #1], 
  Appearance -> "Palette", 
  ImageSize -> 250] &) /@ {"DisplayFormula", 
"DisplayFormulaNumbered"};

button2 = 
 Button[Style["Copy Reference", 14, FontFamily -> "Calibri"], 
  Module[{cell, tags, tag, createTag}, 
   cell = First[
     Cells[NotebookSelection[InputNotebook[]], 
     CellStyle -> "DisplayFormulaNumbered"], 
     MessageDialog["Select an equation cell!"];
     Return[]];
 tags = 
     Replace[CurrentValue[cell, CellTags], t : Except[_List] :> {t}];
 createTag := 
     With[{newTag = CreateUUID["eqnID-"]}, 
     SetOptions[cell, 
     CellTags -> Append[Select[tags, Not@*StringMatchQ["eqnID-*"]], newTag]]; newTag];
 tag = SelectFirst[tags, StringMatchQ["eqnID-*"], createTag];
 If[Length[Cells[InputNotebook[], CellTags -> tag]] > 1, 
  MessageDialog[
  "Multiple cells with same  tag found!\nTag of current cell will be  regenerated."];
  tag = createTag];
 With[{tag = tag}, 
  CopyToClipboard[
   Button[Row[{"(", 
     Dynamic[CurrentValue[
       First[Cells[CellTags -> tag], $Failed], {"CounterValue", 
        "DisplayFormulaNumbered"}]], ")"}], 
   Appearance -> None]]]], Appearance -> "Palette"];

pastebutton = 
  Button[Style["Paste Reference", 14, FontFamily -> "Calibri"], 
  Paste[], Appearance -> "Palette"];

CreatePalette[
  Column[Join[stylebuttons, {button2, pastebutton}], Spacings -> 0, 
  Alignment -> Center], Saveable -> False, 
  WindowTitle -> "Cell Styles & Cell Ref"];

The palette looks like this:

enter image description here

I want to add buttons to the palette that perform the following operations:

  1. Insert the text <esc>am<ec> (i.e., insert an invisible alignment marker)
  2. Format -> Text Alignment -> On AlignmentMarker

Is this possible? How?

If item (1) is impossible, (2) would still be useful.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.