When I look at a visible moon in daylight its phase is shown at an angle. However textbook moon phase diagrams only show the phase vertically. What is it that determines the angle? The reason I ask this questions is the Moon's illumination is not in direct line with the position of the visible sun.
The angle that the moon appears to be tilted depends on the relative positions of the sun and moon. The lit part of the moon always points at the sun, but it points at the sun along a "great circle", and this can create an optical illusion, since a line in the sky that is parallel to the horizon could appear "straight" but it is not a great circle. Since we tend to judge things relative to the horizon, this can give the impression that the lit part of the moon isn't pointing at the sun.
The angle is fully determined by the relative positions of the moon and sun. So, for example, in winter, the crescent moon will appear more "upright" in the evening, since the slope of the ecliptic tends to be more shallow. Moreover in the tropics, where the angle is steeper, the crescent moon's horns will be pointing up (giving rise to the Hawaiian notion of a "wet moon")
In textbooks, the moon is drawn (or the photograph of the moon is rotated) to the vertical, for convenience. It makes the comparison between the phases simpler if they are all drawn at the same angle.