diff --git a/packages/ckeditor5-math/src/mathcommand.ts b/packages/ckeditor5-math/src/mathcommand.ts index 63671f437..b6126f42f 100644 --- a/packages/ckeditor5-math/src/mathcommand.ts +++ b/packages/ckeditor5-math/src/mathcommand.ts @@ -33,10 +33,18 @@ export default class MathCommand extends Command { { equation, type, display } ); } else { + const selection = this.editor.model.document.selection; + // Create new model element mathtex = writer.createElement( display ? 'mathtex-display' : 'mathtex-inline', - { equation, type: outputType, display } + { + // Inherit all attributes from selection (e.g. color, background color, size). + ...Object.fromEntries( selection.getAttributes() ), + equation, + type: outputType, + display, + } ); } model.insertContent( mathtex );