Consider the following MWE:
\documentclass{article}
\usepackage{xparse,l3draw,xcolor}
\ExplSyntaxOn
%-----------------------------------------------------------------------------
% Error handling function warning message
\msg_new:nnn { mathicon } { invalid-size }
{ Size~must~be~positive.~Using~default~of~11pt.}
\msg_new:nnn { mathicon } { invalid-shape }
{ The~shape~"#1"~is~not~recognized.~Using~a~square~by~default. }
%-----------------------------------------------------------------------------
% Error handling function for size
\cs_new_protected:Nn \__mi_geo_check_size:n
{
\dim_compare:nNnTF {#1} > { 0pt }
{ \dim_set:Nn \l__mi_geo_size_dim {#1} }
{
\msg_warning:nn { mathicon } { invalid-size }
\dim_set:Nn \l__mi_geo_size_dim { 11pt }
}
}
%-----------------------------------------------------------------------------
% Command to draw the shape with optional size, color, and line thickness
\NewDocumentCommand{\migeoshape}{O{ 11pt } O{ magenta } O{ 0.025 } m}
{
\mi_geo_draw_shape:nnnn { #4 } { #1 } { #2 } { #3 }
}
%-----------------------------------------------------------------------------
% Internal variables
\dim_new:N \l__mi_geo_size_dim
% Function to draw square
\cs_new_protected:Nn \mi_geo_draw_square:
{
\draw_path_rectangle:nn { 0.0\l__mi_geo_size_dim , 0.0\l__mi_geo_size_dim } { 1.0\l__mi_geo_size_dim, 1\l__mi_geo_size_dim }
\draw_path_use_clear:n { stroke }
}
%-----------------------------------------------------------------------------
% Main function to draw the shape with size, color, and line thickness
\cs_new_protected:Nn \mi_geo_draw_shape:nnnn
{
\__mi_geo_check_size:n { #2 }
\draw_begin:
\color_select:n { #3 }
\draw_linewidth:n { #4 \l__mi_geo_size_dim }
\str_case:nnF { #1 }
{
{ square } { \mi_geo_draw_square: } %Use for cases. This is just for testing.
}
{
\msg_warning:nnn { mathicon } { invalid-shape } { #1 }
\mi_geo_draw_square:
}
\draw_end:
}
\ExplSyntaxOff
\begin{document}
\migeoshape[-11pt][red][0.036]{square} Sample
\migeoshape[11pt][black][0.075]{hexagon} % This will default to square with a warning
\end{document}
The first warning works well, but for the second something weird happens. In the image below, (mathicon) appears in the message.
Also, if I find the message in Texmaker, the part (mathicon) square by default. goes to the next line and is not highlighted blue.
Is there a fix to this? Also I would like to add the line number to the warming message. I have not managed to succesfully use \msg_line_context:
Also, if you have any suggestions for my code improvement, let me know.

