Sublime Text - formatting for code alignment - alignment

I am a new coder using Sublime Text. I would like to format the line to have equal spacing as that picture below. How can I do that?
$Fullname = $_POST['fullname'];
$password = $_POST['password'];
$username = $_POST['username'];
$tel = $_POST['tel'];
$address = $_POST['address'];

The Alignment package is probably what you're looking for, although there are many other plugins that perform similar functions with various other options. Alignment is pretty straightforward, aligning on = with at least one space before it. There are also a number of optional preceding characters, so alignment also works with tokens like !=, >=, ~=, etc.
VAlign is a plugin based off Alignment that has some additional options available, such as automatic detection of code to be aligned.

Related

How to align two UILabels on the Y axis of the center of the first line of text

please see the image below for two examples of what is to be achived
the alignment should be on the Center Y of the first lines of each UILabels and should work regardless of font size or font. currently we have implemented this with different constraints to the top of the super view for different font and font size combinations.
the constraint to align the center of the two UILabels does not work since the text of the second UILabel is not fixed and can have several lines.
also the text is dynamic, so it is not known where the text will wrap to create the first line, thus it cannot be shown in an one line UILabel with the rest of the text in another one below.
currently this is implemented using UIKit, but if there is an easy solution in SwiftUI we can put these two labels in a SwiftUI component. so a SwiftUI solution would also be welcomed.
Your comments said "it should be on the glyphs" ... but, without additional information, my guess is that "real world" usage would not really need that level of precision.
For example:
While the glyphs are not perfectly center-Y aligned, it seems unlikely you'd run into a case where the first line of the "rightLabel" is " ' " ' " or . , . , ..
This layout can be easily done with only a few constraints - no need to do any calculations:
The "Positioning" label would, of course, be set .hidden = true so it would never be seen.
If you really, really want glyph-precision, you'll need to calculate
the Glyph bounding box for the left-label
the Glyph bounding box for first line of the right-label
calculate the "character box" offsets to align the Glyph Y-centers
and then position the two labels accordingly, or use Core Text to draw the text (instead of using UILabel).
Probably more work than necessary -- unless your actual use-case demands it.
That's an interesting problem! You can try using the centerYAnchor for the label on the left, and the firstBaselineAnchor for the label on the right... that will align the center Y with the text baseline, which isn't quite what you want.
To find the correct offset to apply, you can use the information from UIFont about the size of the characters. I'd probably start with capHeight * 0.5 and see if that looks or feels right. Something like:
leftLabel.centerYAnchor.constraint(equalTo: rightLabel.firstBaseLineAnchor, constant: rightFont.capHeight * 0.5)
This is a more difficult problem in SwiftUI, I think, because resolved font metrics aren't directly available to you.

MathJax Font Size

In MathJax, I am able to adjust the font size using the answer here (i.e. shown below). Is there a way to adjust the font size of the normal text too without dollar signs around it too? For example, when I type the following: Let $f(x)=x^2$.
The text size around the word "Let" would be small and $f(x)=x^2$ would be much larger. I want to scale the text of the words as well, and I am not sure how to do so.
chtml: {scale: 1.5},
svg: {scale: 1.5},
In regular Latex, you could do Let $f(x)=x^2$.
However remember that, as the name suggests, MathJax doesn't aim to make all of Latex available to the web but focuses on the math part of Latex (and also AsciiMath and MathML of course). A key thing to remember here is that MathJax actually uses the math delimiters to find where there are content to typeset and when you do Let $f(x)=x^2$, MathJax doesn't do anything about the Let since it is outside the math delimiters.
Nonetheless, there are ways to use regular text in Latex math mode too. For example by means of \text{} so in your case, you could accomplish what you want with $\text{Let } f(x)=x^2$
Now, simply setting the text size of the surrounding content will make all of the Latex bigger:
<p style="font-size: 1.5em;">$\text{Let } f(x)=x^2$</p>
<p style="font-size: 2.5em;">$\text{Let } f(x)=x^2$</p>
<p style="font-size: 5em;">$\text{Let } f(x)=x^2$</p>
If you want a bigger horizontal space between the math and the Let, you can add a horizontal spacer:
<p>$\text{Let}\hspace{2mm} f(x)=x^2$</p>
I have prepared a sandbox which you can play around with, also try to uncomment the scale part of the configuration to see this factor in play (however, I usually use font height and not scale to control size): Sandbox
Some things to remember:
Example uses MathJax 3, there might be small differences in comparison to version 2.
Example uses the HTML output processor (as in your example), if you load a different MathJax script, you might be outputting svgs instead and then some options won't have impact, so always check these things thoroughly when something doesn't work.
$...$ is not a standard pair of delimiters so it has to be explicitly configured, otherwise MathJax won't recognize it as inline Latex math.
MathJax automatically does one round of initial typesetting, if you want to update content dynamically, you have to explicitly instruct MathJax to typeset again.
Good luck!

How can I standardize the the varying truncating dot characters of UILabel?

I have a plist file which I decode to load data onto my application.
This plist file contains String type values that gets mapped to UILabel's text property.
I noticed that the truncating behavior of the text in the label is not always the same.
To be more specific, the three dots that are added when the text is truncated are, as opposed to my expectation, two kinds: one being ... and the other being ⋯ which appears to be this unicode character in this link.
I checked UILabel's attribute settings but I was unable to find any settings related to this behavior.
Has anyone else experienced this problem and standardized the truncating character to be ...?
Here is the image describing the problem mentioned above. Both labels have 2 lines and have new line escape character inserted between the first line and the second line of text. I am posting a link to this image because apparently I don't have enough reputation to post an image.
varying truncating characters of UILabel
IMO this is a bug in UILabel, and it may be worth opening a Feedback about it.
TL;DR: I recommend using TTTAttributedLabel.
Long-winded answer, because this was such an interesting question:
UILabel uses a different ellipsis based on the language script being truncated. As you've noticed, for most scripts, they use HORIZONTAL ELLIPSIS (…), or something very similar. But for Chinese, Japanese, and Korean (CJK), they use MIDLINE HORIZONTAL ELLIPSIS (⋯), or again, something very similar. The only other exception I've found is Burmese, which uses three circles that I don't recognize.
In my tests, all the following used …: Latin, Cyrillic, Bengali, Arabic, Hebrew, Hindi, Thai, Kannada, Nepali, and Mongolian (I kid. iOS can't layout Mongolian. Nobody can layout Mongolian, but it still uses …). UILabel even uses … for Lao, even though I thought ຯ was specifically for that, but I guess eventually everything becomes Latin.
The problem with UILabel being so clever for CJK and Burmese is that it decides what character to use exclusively by looking at the first character being removed. And it thinks SPACE is Latin (or at least not "special").
So what to do? My recommendation is probably to use TTTAttributedLabel, since it lets you configure the truncation character, and more importantly, is open source so you can fix it if it's not working the way you want.
The second option would be to truncate the text by hand using techniques like the one described in How to change truncate characters in UILabel?. There are probably better ways to do it using CTFrameGetVisibleStringRange instead of constantly shrinking the string until it fits, but I don't know if it's worth the effort. (If that path sounds useful, I could probably write up something that does it. It's just probably not worth the trouble.)
And the final option I know is to replace the SPACE character with an "equivalent" CJK character. The closest I've found that works is HANGUL FILLER (U+3164), but I don't like it. It's too wide, and I expect that it will make Korean uncomfortable to read (but I rarely try to read Korean, so I may be wrong here):
With SPACE: 안녕 하세요
With FILLER: 안녕ㅤ하세요
There's also HALFWIDTH HANGUL FILLER (U+FFA0), which is better, but UILabel seems to make it zero width (this may be a font issue, so maybe worth trying):
With SPACE: 안녕 하세요
With HALF: 안녕ᅠ하세요
let string = "안녕 하세요"
let filler = "\u{3164}"
label.text = string.replacingOccurrences(of: " ", with: filler)
OTOH, you may run into the same problem if you use any other non-CJK characters, like Latin punctuation or Arabic numerals. So this solution may not scale. And you should make sure that Voice Over properly ignores it.

Line fill for UITextView?

Is there a property that will apply the proper character spacing to have all the text on each line in an NSAttributedString butt up against the bounds like in a book, (including the final line which I know isn't done in books)? I know kerning can be adjusted, but that won't dynamically adjust on a per line basis. Any help would be appreciated. Also NSTextAlignmentJustified and NSTextAlignmentNatural get close, but won't apply the effect to the last line of text.
The only option is to use NSTextAlignmentJustified. Last line is never justified, because NSTextAlignmentJustified refers to Left Justification mode, as it is the standard case.
For more information you can take a look at Typographic Alignment on wikipedia : http://en.wikipedia.org/wiki/Typographic_alignment

iOS: Better justification with CoreText

I'm floating some text around an image using CoreText and kCTJustifiedTextAlignment to show the text justiefied - but with larger images, smaller text-areas and less whitespaces CoreText does not only widen whitespaces but also the margin between the letters.
See here:
This sometimes looks really awful, so I searched for some alternatives or workarounds but only found the advice to do it myself by adding more whitespaces after each whitespace to match the width and using kCTLeftTextAlignment.
It sounds like a lot of snares to deal with, so I thought, I'd ask here, maybe anyone has an idea how to deal with that issue.
The basic question here is "so what do you want?" The other obvious answer is "full justify unless... some rules I'm going to make up like if there's only one word."
If you want that kind of control, then you need to drop down to the CTLine level and create justified lines only when you want them. Assuming you already know a bit about CoreText, this code should hopefully make sense. It justifies the line only if it isn't the last line of the paragraph.
CFIndex lineCharacterCount = CTTypesetterSuggestLineBreak(self.typesetter, startIndex, boundsWidth);
CTLineRef line = CTTypesetterCreateLine(self.typesetter, CFRangeMake(startIndex, lineCharacterCount));
// Fetch the typographic bounds
CTLineGetTypographicBounds(line, &(*ascent), &(*descent), &(*leading));
// Full-justify all but last line of paragraphs
NSString *string = self.attributedString.string;
NSUInteger endingLocation = startIndex + lineCharacterCount;
if (endingLocation >= string.length || [string characterAtIndex:endingLocation] != '\n') {
CTLineRef justifiedLine = CTLineCreateJustifiedLine(line, 1.0, boundsWidth);
CFRelease(line);
line = justifiedLine;
}
So we create a normal CTLine based on the CTTypesetter suggestion. Then we apply some rule (only one word? Not the end of the paragraph? Whatever.) If we pass, then we create a new, justified line. (I'm not certain why CTTypesetter can't create a justified line itself.)
For a full example of this, see PinchText. It's much more complicated than you need, but it shows how to do all the layout with lots of comments.

Resources