from bs4 import BeautifulSoup


def new_float(float_class: str, content, caption, id=None):
	"""Creates a float using the <float> tag. 
	Parameters:
	- float_class: A string specifying the type of float, e.g. "Figure".
	- content: Whatever you want to put in this float. It can be anythin
	accepted by the "append" method of BeautifulSoup (e.g. a string with
	the HTML code as well as a tag object).
	- caption: The caption. It can be anything accepted by the "append"
	method of BeautifulSoup (e.g. a string with the HTML as well as a 
	tag object).
	Returns:
	- The float tag.
	- """
	if not isinstance(float_class, str):
		raise TypeError(f'<float_class> must be a string, received object of type {type(float_class)}.')
	float_tag = BeautifulSoup(features='lxml').new_tag('float')
	float_tag['class'] = float_class
	float_tag.append(content)
	caption_tag = BeautifulSoup(features='lxml').new_tag('floatcaption')
	caption_tag.append(caption)
	float_tag.append(caption_tag)
	if isinstance(id, str):
		float_tag['id'] = id
	return float_tag