@@ -232,19 +232,58 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
232232 kind : 'function' ,
233233 latexTrigger : '\\tr' ,
234234 arguments : 'implicit' ,
235- serialize : ( serializer : Serializer , expr : Expression ) : string => {
236- const arg = operand ( expr , 1 ) ;
237- const argLatex = serializer . serialize ( arg ) ;
238- // Use \tr A for simple args, \tr\left(...\right) for complex ones
239- if ( typeof arg === 'string' || typeof arg === 'number' )
240- return `\\tr ${ argLatex } ` ;
241- return `\\tr\\left(${ argLatex } \\right)` ;
242- } ,
235+ serialize : ( serializer : Serializer , expr : Expression ) : string =>
236+ serializeImplicitOperator ( serializer , expr , '\\tr' ) ,
243237 } ,
244238
245239 // Also support plain text: tr(A)
246240 { symbolTrigger : 'tr' , kind : 'function' , parse : 'Trace' , arguments : 'implicit' } ,
247241
242+ {
243+ name : 'Kernel' ,
244+ kind : 'function' ,
245+ latexTrigger : '\\ker' ,
246+ arguments : 'implicit' ,
247+ serialize : ( serializer : Serializer , expr : Expression ) : string =>
248+ serializeImplicitOperator ( serializer , expr , '\\ker' ) ,
249+ } ,
250+ { symbolTrigger : 'ker' , kind : 'function' , parse : 'Kernel' , arguments : 'implicit' } ,
251+
252+ {
253+ name : 'Dimension' ,
254+ kind : 'function' ,
255+ latexTrigger : '\\dim' ,
256+ arguments : 'implicit' ,
257+ serialize : ( serializer : Serializer , expr : Expression ) : string =>
258+ serializeImplicitOperator ( serializer , expr , '\\dim' ) ,
259+ } ,
260+ {
261+ symbolTrigger : 'dim' ,
262+ kind : 'function' ,
263+ parse : 'Dimension' ,
264+ arguments : 'implicit' ,
265+ } ,
266+
267+ {
268+ name : 'Degree' ,
269+ kind : 'function' ,
270+ latexTrigger : '\\deg' ,
271+ arguments : 'implicit' ,
272+ serialize : ( serializer : Serializer , expr : Expression ) : string =>
273+ serializeImplicitOperator ( serializer , expr , '\\deg' ) ,
274+ } ,
275+ { symbolTrigger : 'deg' , kind : 'function' , parse : 'Degree' , arguments : 'implicit' } ,
276+
277+ {
278+ name : 'Hom' ,
279+ kind : 'function' ,
280+ latexTrigger : '\\hom' ,
281+ arguments : 'implicit' ,
282+ serialize : ( serializer : Serializer , expr : Expression ) : string =>
283+ serializeImplicitOperator ( serializer , expr , '\\hom' ) ,
284+ } ,
285+ { symbolTrigger : 'hom' , kind : 'function' , parse : 'Hom' , arguments : 'implicit' } ,
286+
248287 {
249288 name : 'Determinant' ,
250289 kind : 'function' ,
@@ -262,11 +301,7 @@ export const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary = [
262301 stringValue ( operand ( arg , 2 ) )
263302 ) ;
264303 }
265- const argLatex = serializer . serialize ( arg ) ;
266- // Use \det A for simple args, \det\left(...\right) for complex ones
267- if ( typeof arg === 'string' || typeof arg === 'number' )
268- return `\\det ${ argLatex } ` ;
269- return `\\det\\left(${ argLatex } \\right)` ;
304+ return serializeImplicitOperator ( serializer , expr , '\\det' ) ;
270305 } ,
271306 } ,
272307
@@ -314,6 +349,21 @@ function parseColumnFormat(parser: Parser, optional = true): string {
314349 return result ;
315350}
316351
352+ function serializeImplicitOperator (
353+ serializer : Serializer ,
354+ expr : Expression ,
355+ command : string
356+ ) : string {
357+ const args = operands ( expr ) ;
358+ if ( args . length !== 1 ) return `${ command } ${ serializer . wrapArguments ( expr ) } ` ;
359+ const arg = operand ( expr , 1 ) ;
360+ const argLatex = serializer . serialize ( arg ) ;
361+ // Use \foo A for simple args, \foo\left(...\right) for complex ones
362+ if ( typeof arg === 'string' || typeof arg === 'number' )
363+ return `${ command } ${ argLatex } ` ;
364+ return `${ command } \\left(${ argLatex } \\right)` ;
365+ }
366+
317367function serializeTabular (
318368 serializer : Serializer ,
319369 rows : ReadonlyArray < Expression > ,
0 commit comments