;;--------------rtomtftin.lsp----------------------------- ;;; Author: Herman Mayfarth ;;; Date: 7 May 2003 ;;; Purpose: convert real to MTEXT representation of ft & inches ;;; w/ choice of fraction style ;;; Params: num: real number to convert to MTEXT string ;;; fracht: real specifying the relative ht. of fractions ;;; barsty: string specifying fraction bar style ;;; this must be one of '("/" "^" "#") ;;; Returns: string as above if successful, nil otherwise ;;; Calling function must provide the vertical alignment code ;;;------------------------------------------------------ (defun rtomtftin (num fracht barsty / add count curent instrg outstrg start_format suffix ) (setq instrg (rtos num 4 4)) (if (member barsty '("/" "^" "#"));character is allowed (progn ;call the function ;;three cases exist: ;;Case 1: ;;if we have > 1" and have a fraction, the string will contain a space before ;;the fraction, and we need to substitute the start of the MTEXT format for ;;the space character ;;Case 2: ;;we have >1" but no fraction => no / will be found, and no MTEXT formatting ;;Case 3: ;;we have a fraction <1" => MTEXT formatting prefixes the input string ;setup the format string for the start of the MTEXT fraction (setq start_format (strcat "{\\H" (rtos fracht 2 2) "x;\\S") ;initialize a counter for the position to test in the input string count 1 suffix 0 ;and bind a null string to a symbol for the output string outstrg "") ;now walk down the input string one character at a time (repeat (strlen instrg) ;set a flag to indicate the current character should be kept (setq add 1 ;and get the current character from the input string curent (substr instrg count 1)) ;;first, test for a space character (cond ((= curent " ");found a space (Case 1), ;; so substitute the fraction format, clear the add flag, and set a flag ;; to let us know we need to close the format at the end (setq outstrg (strcat outstrg start_format) add nil suffix 1)) ;;else test for fraction bar ((= curent "/") ;found a fraction bar (progn ;;;test for suffix (if (= suffix 0) (setq suffix 2));need a prefix ;;substitute the value of barsty if necessary, clear the add flag (if (/= barsty "/");rtos always uses / (setq outstrg (strcat outstrg barsty) add nil ) ) );progn );pred );cond ;if add is bound, there was no substitution, so just add the ;current character to the front of the output string (if add (setq outstrg (strcat outstrg curent))) (setq count (1+ count)) );repeat ;;if we found a fraction, we need to close the MTEXT format (cond ((= suffix 1) (setq outstrg (strcat outstrg ";}"))) ((= suffix 2) (setq outstrg (strcat start_format outstrg ";}"))) (T nil);otherwise, do nothing ) outstrg );progn ;;do nothing, disallowed separator );if );rtomtftin