This paper describes a formalism for the justification of texts written in an Arabic alphabet‑based script, within some approved calligraphic rules, that would produce better typographical quality than current publishing systems. Specifically, we improve the optimum-fit algorithm by taking into account the existence of allographic variants and stretched forms with kashida (a feature in some cursive alphabets) provided by the font. This sophisticated algorithm breaks the paragraph into lines in an optimal way; it does not just justify each line. Thus, it allows selecting the optimal version among several variants. This approach could be extended for the composition of multilingual texts.