# Construct a function with subindices

I'm constructing a function that gives me subindices in output.
The function is HAt.

For example:

HAt[u == u0, t -> 0] The function is constructed following:

HAt/:MakeBoxes[HAt[eq_, x_-> n_], StandardForm]:=
RowBox[
{SubscriptBox[
RowBox[{"", ToBoxes[eq[]], ")"}],
RowBox[{ToBoxes[x], "=", ToBoxes[n]}]],
"\[Equal]",
SubscriptBox[
RowBox[{"(", ToBoxes[eq[]], ")"}],
RowBox[{ToBoxes[x],"=",ToBoxes[n]}]]}]


So, the problema is when the right-hand (or left-hand) of my equation is a number. For example, if I put:

HAt[u == 0, t -> 0] But I want some like this: I think the ideia is put some condition at eq[] when this term is a numerical term, some like that:

HAt/:MakeBoxes[HAt[eq_, x_ -> n_] /; eq[]_Numeric, StandardForm] :=
RowBox[
{SubscriptBox[
RowBox[{"(",ToBoxes[eq[]],")"}],
RowBox[{ToBoxes[x], "=", ToBoxes[n]}]],
"\[Equal]",
ToBoxes[eq[]]}]


But the above doesn't work. How do I write the condition I want to enforce correctly?

• Why not do this with PatternTest? Also Numeric isn't a thing... NumericQ is though. – b3m2a1 Jan 29 '19 at 21:01
• Solved, thank you @b3m2a1 – Mateus Jan 29 '19 at 21:20

## 1 Answer

When playing with typesetting the most important thing is to keep your input unevaluated. In cases like Hold @ HAt[...] MakeBoxes won't know that Hold is there.

There are several things that can cause evaluation leaks:

• ToBoxes[x] will evaluate x, use MakeBoxes

• eq[] will evaluate eq, use lhs_ == rhs_ to match your equations

• ?NumericQ will evaluate as well as opposed to e.g. _Real but the latter is not general enough. Fortunately there is SystemDumpHeldNumericQ :)

Here is how I'd do this:

HAt // ClearAll;
HAt /: MakeBoxes[HAt[lhs_ == rhs_, x_ -> n_], fmt : StandardForm] := With[
{ subscript = SubscriptBox[RowBox[{"(", #, ")"}], RowBox[{MakeBoxes[x, fmt], "=", MakeBoxes[n, fmt]}]] &
}
, RowBox[{
subscript @ MakeBoxes[lhs, fmt]
, "\[Equal]"
, If[SystemDumpHeldNumericQ[rhs], Identity, subscript] @ MakeBoxes[rhs, fmt]
}]
]
{"ft_lang_label":"__label__en","ft_lang_prob":0.5912585,"math_prob":0.98788667,"size":1057,"snap":"2021-04-2021-17","text_gpt3_token_len":345,"char_repetition_ratio":0.14529915,"word_repetition_ratio":0.0,"special_character_ratio":0.3604541,"punctuation_ratio":0.22790697,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99735653,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,5,null,5,null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-15T02:01:03Z\",\"WARC-Record-ID\":\"<urn:uuid:7f72f117-3a1d-4203-8e82-4a3116f814a3>\",\"Content-Length\":\"167863\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bbc79b16-5485-453f-8361-8106aa7b6fde>\",\"WARC-Concurrent-To\":\"<urn:uuid:6e138e87-80b3-4047-872a-21f1dc0fc55f>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/questions/190487/construct-a-function-with-subindices\",\"WARC-Payload-Digest\":\"sha1:QA22BBKEOTOB4WV242M2WCX33KU6H7UT\",\"WARC-Block-Digest\":\"sha1:MF5JXB5BHQWROIAK7FO4THIB3CIQVTJV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038082988.39_warc_CC-MAIN-20210415005811-20210415035811-00018.warc.gz\"}"}